- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何控制哪个用户拥有我要复制到容器中或从容器中复制的文件?
docker cp
command表示有关文件所有权的信息:
The
cp
command behaves like the Unixcp -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 withUID:GID
of the root user. Files copied to the local machine are created with theUID:GID
of the user which invoked thedocker cp
command. However, if you specify the-a
option,docker cp
sets the ownership to the user and primary group at the source.
-a
选项似乎没有什么区别。
$ sudo chown 1005:1005 test.txt
$ ls -l test.txt
-rw-r--r-- 1 1005 1005 29 Oct 6 12:43 test.txt
$ docker volume create sandbox1
sandbox1
$ docker run --name run1 -vsandbox1:/data alpine echo OK
OK
$ docker cp test.txt run1:/data/test1005.txt
$ docker cp -a test.txt run1:/data/test1005a.txt
$ sudo chown 1006:1006 test.txt
$ docker cp test.txt run1:/data/test1006.txt
$ docker cp -a test.txt run1:/data/test1006a.txt
$ docker run --rm -vsandbox1:/data alpine ls -l /data
total 16
-rw-r--r-- 1 1005 1005 29 Oct 6 19:43 test1005.txt
-rw-r--r-- 1 1005 1005 29 Oct 6 19:43 test1005a.txt
-rw-r--r-- 1 1006 1006 29 Oct 6 19:43 test1006.txt
-rw-r--r-- 1 1006 1006 29 Oct 6 19:43 test1006a.txt
-a
选项似乎什么也没做。
$ docker run --rm -vsandbox1:/data alpine cp /data/test1006.txt /data/test1007.txt
$ docker run --rm -vsandbox1:/data alpine chown 1007:1007 /data/test1007.txt
$ docker cp run1:/data/test1006.txt .
$ docker cp run1:/data/test1007.txt .
$ docker cp -a run1:/data/test1006.txt test1006a.txt
$ docker cp -a run1:/data/test1007.txt test1007a.txt
$ ls -l test*.txt
-rw-r--r-- 1 don don 29 Oct 6 12:43 test1006a.txt
-rw-r--r-- 1 don don 29 Oct 6 12:43 test1006.txt
-rw-r--r-- 1 don don 29 Oct 6 12:47 test1007a.txt
-rw-r--r-- 1 don don 29 Oct 6 12:47 test1007.txt
-rw-r--r-- 1 1006 1006 29 Oct 6 12:43 test.txt
$
最佳答案
除了@Don Kirkby的答案外,让我在bash/shell脚本中提供一个类似的示例,以供您在将与原始文件的所有权和权限不同的情况下复制到容器中的情况。
让我们从一个小图像创建一个新容器,该容器将继续运行:
docker run -d --name nginx nginx:alpine
touch foo.bar
ls -ahl foo.bar
>> -rw-rw-r-- 1 my-user my-group 0 Sep 21 16:45 foo.bar
UID
并保留权限:
docker cp foo.bar nginx:/foo.bar
docker exec nginx sh -c 'ls -ahl /foo.bar'
>> -rw-rw-r-- 1 4098 4098 0 Sep 21 14:45 /foo.bar
tar
解决方法,我可以更改在容器内部应用的所有权和权限。
tar -cf - foo.bar --mode u=+r,g=-rwx,o=-rwx --owner root --group root | docker cp - nginx:/
docker exec nginx sh -c 'ls -ahl /foo.bar'
>> -r-------- 1 root root 0 Sep 21 14:45 /foo.bar
tar
选项说明:
c
创建一个新的存档,而不是解压缩一个存档。 f -
将写入stdout
而不是文件。 foo.bar
是要打包的输入文件。 --mode
指定目标的权限。与chown
相似,它们可以符号表示或八进制数形式给出。 --owner
设置文件的新所有者。 --group
设置文件的新组。 docker cp -
从
stdin
读取要复制到容器中的文件。
docker exec
不是选项(只能在正在运行的容器上运行)。
关于docker - docker cp之后的文件所有权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46613326/
我想知道是否有一个相同的命令可以像使用旧的 MS-DOS 一样将文件夹复制到当前目录。假设我当前的目录位置是: /var/www/ 我有文件夹和文件: /home/hope/subfolder/doc
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a software
我有一个项目,其中一个目录最初(数百次提交前)是从另一个目录逐字复制的,但是没有使用 svn cp 所以历史上有一个断开连接。现在是否可以在初始复制点连接两个目录,还是为时已晚? 最佳答案 让我猜猜你
我一直在寻找一种方法来 cp 文件并同时将其权限修改为 400...在 public_html 文件夹中进行了一些测试之后... public_html >> ls -lah -rw-r--r--
如果lib/目录下只包含.jar文件,有什么区别 java -cp "lib/*" ... 和 java -cp "lib/*.jar" ... 如果我使用后者,我会遇到关于主类的错误,我不明白为什么
我注意到 javac 和 java 选项的大小写敏感性似乎有所不同。例如: 区分大小写的 javac 命令选项? -cp Yes -sourcepath Yes -d
我以前从来没有遇到过这个问题,当我去运行 Java 程序(在终端中)时,我会简单地说, java className 然后程序就会运行。但是最近当我尝试这个时我得到了错误, could not
我有两个问题: 为什么 javac -cp 不需要 .? $ javac -cp /home/t/programs/java/test/junit-4.11.jar TestCase.java 为什么
根据 Linux 中的管道方法,第一个命令的输出应该被视为第二个命令的输入。所以当我在做 which cp | ls -l,应该当作ls -l $(which cp) 但输出显示的是其他内容。 为什么
有什么区别 cp -R source_path target_path 对比 cp -R source_path/* target_path 我发现第二个 cmd 在我的 amazon linux 系
根据标准: A copy/move constructor for class X is trivial if it is not user-provided and if — class X has
当我对 grep 执行 ls 时,结果正是我所需要的:dll 列表,见下文: $ ls -R | grep "dll$" boost_chrono-vc90-gd-1_47.dll boost_c
出于工作需要,使用aws Java SDK实现“aws s3 cp”命令会很方便。 有现成的类,例如TransferManager,AmazonS3Client有get方法。他们可以轻松地将文件下载到
背景 我有两个图像文件夹...文件夹一是包含数千张彩色图像的主文件夹。文件夹二是一个经过过滤的文件夹,其中包含我一直在整个文件夹一中寻找的内容,但文件夹二中的图像是黑白的。 特别说明 – 文件夹二中的
大家好,我正在使用 GCE,现在我是存储桶的新手。我的另一个桶上有很多照片。我尝试将其复制为 sudo gsutil cp -R dir dir 我花了 30 分钟仍未完成文件复制,所以我尝试了使用
我正在尝试从命令行编译并运行程序。当我们编译它时,我们执行 -cp 并将其链接到我们的 jdbc jar。 javac -cp jdbc.jar *.java 如果我们这样做: java调试器 然后我
我正在编写一个脚本来设置 debian 安装,这个错误让我很沮丧: 问题: cp "$BASHRC" "$HOME"/.bashrc 给出: + sudo -u billy bash cp: cann
#!/bin/bash # Make a txt copy of any html files for value in $1/*.html do if [[ $value == *.
我有一个大文件正在移动。实验室中的正常协议(protocol)是将其复制到某处,然后将其删除。 我决定改成mv。 我的问题是,为什么 mv 比 cp 快这么多? 为了测试它,我生成了一个 2.7 GB
我有一个大文件正在移动。实验室中的正常协议(protocol)是将其复制到某处,然后将其删除。 我决定改成mv。 我的问题是,为什么 mv 比 cp 快这么多? 为了测试它,我生成了一个 2.7 GB
我是一名优秀的程序员,十分优秀!