gpt4 book ai didi

postgresql - docker cp from local into container 得到了奇怪的用户组

转载 作者:行者123 更新时间:2023-11-29 13:14:03 25 4
gpt4 key购买 nike

我开始从 docker run --name postgres -e POSTGRES_PASSWORD=passwd -d postgres

中提取最新的官方 postgres docker 镜像

然后我运行以下命令,docker cp colors.csv postgres:/colors.csv

但是在docker cp之后,复制的文件是在一个奇怪的用户组中创建的,而不是root用户。

xuanyue$ docker exec -it postgres ls -ahl
total 80K
drwxr-xr-x 1 root root 4.0K Jul 16 18:54 .
drwxr-xr-x 1 root root 4.0K Jul 16 18:54 ..
drwxr-xr-x 1 root root 4.0K Jul 2 23:39 bin
drwxr-xr-x 2 root root 4.0K Feb 23 23:23 boot
-rwxrwxrwx 1 120042327 120042327 251 Jul 16 18:38 colors.csv

这是为什么呢?我知道我可以通过 chown 轻松更改它,但只是好奇

最佳答案

这是一个非常令人不安的行为,因为与 docker cp in the docs 的描述中所写的结果相比,结果是出乎意料的。 :

The cp command behaves like the Unix cp -a command in that directories are copied recursively with permissions preserved if possible. Ownership is set to the user and primary group at the destination. For example, files copied to a container are created with UID:GID of the root user. Files copied to the local machine are created with the UID:GID of the user which invoked the docker cp command. However, if you specify the -a option, docker cp sets the ownership to the user and primary group at the source.

但我发现许多与此行为相关的未解决问题/PR:

我认为这将在未来版本的 Docker 中得到修补;等待,您必须假设本地文件的 UID:GID 在将文件复制到容器后得到保存。在您的示例中,colors.csv 可能在您的主机上有 UID=120042327GID=120042327(检查 stat colors.csv 在你的主机上),这就是你在你的容器中得到这个结果的原因。此外,这里 120042327 不匹配容器中的任何用户/组,但如果是这样,您可能已经看到一些奇怪的用户/组拥有该文件(对应于 的用户/组120042327 用户/组)。

关于postgresql - docker cp from local into container 得到了奇怪的用户组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51368568/

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