gpt4 book ai didi

docker - 在 Dockerfile 中使用显式 UID/GID

转载 作者:行者123 更新时间:2023-12-02 18:21:11 25 4
gpt4 key购买 nike

最佳实践页面提到以下内容:
(https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#user)

Consider an explicit UID/GID
Users and groups in an image are assigned a non-deterministic UID/GID in that the “next” UID/GID is assigned regardless of image rebuilds. So, if it’s critical, you should assign an explicit UID/GID."

明确指定 UID/GID 有什么意义?
在什么情况下允许系统分配 UID/GID 不能提供足够的安全性?

显式指定这些值似乎会导致显式指定的值 (UID/GID) 已在使用中的情况。

最佳答案

我认为这对于某人可能依赖于特定数字 uid 的情况更为重要,可能是将数据注入(inject)容器中。

# this needs to be readable by the container process
# it runs as non-root user "www-data"
# we think its uid is 18
sudo chown -R 18 data
sudo docker run -v ./data:/data -p 8888:80 imagename

现在,如果由于图像作者或最终用户无法控制的基础图像发生变化, adduser使 uid 变成别的东西,这样的配方会中断(主机无法直接查看容器的 /etc/passwd 文件以了解实际的 uid 将是什么)。

要解决这个问题,您可能需要这样的食谱:

# may or may not work to get the uid
CONTAINER_UID=$(sudo docker run --rm imagename id -u)
sudo chown -R "$CONTAINER_UID" data

关于docker - 在 Dockerfile 中使用显式 UID/GID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52264775/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com