即使经过大量 Material 和 SO 答案,我仍然不清楚 docker uid/user 使用或实现。
我理解以下几点:
综上所述,当我的 Dockerfile 中有以下命令时,我假设将创建一个新用户 (
my-user
) 并增加 uid。RUN addgroup my-group && adduser -D my-user -G my-group
uid
分配给所有进程? uid
或相同 uid
和上一个一样? uid
怎么了增量发生在与主机相关的容器中。 任何指针都会有所帮助。
最佳答案
缺席 user namespace remapping ,只有两件事很重要:
/etc/passwd
里面有什么|文件。 请记住,每个容器和主机都有单独的文件系统,所以这些东西中的每一个都可以有单独的
/etc/passwd
文件。What happens if I run the same image multiple times i.e multiple containers? Will the same uid be assigned to all processes?
是的,因为每个容器都会获得相同
/etc/passwd
的副本来自图像的文件。What happens if I add same above command in another image and run that image as container? - will I get new uid or same uid as the previous one?
这取决于什么
adduser
确实如此;它可以相同或不同。How the uid increment happens in Container in relation with the host machine.
他们是完全独立的。
还记得你可以
docker push
/docker pull
在不同的主机上运行它的构建镜像。这将带来图像的 /etc/passwd
文件连同它,但主机环境可能完全不同。相应地,尝试在 Dockerfile 中匹配某些特定主机的 uid 映射不是最佳实践,因为如果您尝试在其他任何地方运行相同的图像,那将是错误的。
关于docker - 了解 Docker 用户/uid 创建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55585091/