我在 Debian 中以 无根模式 运行我的 docker 容器,作为没有 root 权限的 systemd 用户单元(例如,作为用户
1111
)。此外,无根模式使用 userns-remap 来运行带有 subuids/subgids 的容器,因此由 1111
启动的容器实际上将作为 363143
运行。
这会带来更多的麻烦,而不是其价值,对我来说,主要目标是通过以非 root 身份运行 docker 守护进程来实现。如何禁用 userns-remap 并将所有容器运行为
1111
?
或者,如果无法禁用 userns-remap,我可以将其配置为不使用从
363143
开始的 subuid,而是始终使用 1111
吗?
也许有帮助:在 Docker 版本 25.0.2 中,构建以无根模式运行的 29cf629,奇怪的是,可以禁用 userns,但只能使用以下未记录的语法:
docker run --rm -it -v "$(pwd):/tmp",userns=host --user $(id -u):$(id -g) mambaorg/micromamba:1.5.8 /bin/bash
或
docker run --rm -it -v "$(pwd):/tmp"--userns=host --user $(id -u):$(id -g) mambaorg/micromamba:1.5.8 /bin/bash
但不是
docker run --rm -it -v "$(pwd):/tmp" --userns=host --user $(id -u):$(id -g) mambaorg/micromamba:1.5.8 /bin/bash
在前两种情况下,可以从容器内的非 root 用户写入工作目录,如下所示
touch /tmp/test.txt
但这仅在“userns=host”添加逗号或两个破折号时才有效但中间没有空格。
更多详情请参阅
https://github.com/mamba-org/micromamba-docker/issues/407#issuecomment-2086975933