Docker cp 与 Unix cp 工作方式不同的原因是什么?
What are the reasons Docker cp works differently to Unix cp?
假设我有以下目录结构
parent-dir
+ child-dir
+ grandchild-file-a
+ grandchild-file-b
uncle-dir
.
..
现在在 unix 上 - 如果我 运行 命令
parent-dir> cp child-dir ../uncle-dir
那我期望得到
uncle-dir
+ child-dir
+ grandchild-file-a
+ grandchild-file-b
但是如果我用 docker cp
重复这个,我会得到
uncle-dir
+ grandchild-file-a
+ grandchild-file-b
如果我这样做了,这在 unix 上可能是合理的:
parent-dir> cp child-dir/* ../uncle-dir
我的问题是:Docker cp 与 Unix cp 的工作方式不同的原因是什么?
cp
上的 docker 文档解释了这一点:
- SRC_PATH specifies a directory
- DEST_PATH does not exist
- DEST_PATH is created as a directory and the contents of the source directory are copied into this directory
- DEST_PATH exists and is a file
- Error condition: cannot copy a directory to a file
- DEST_PATH exists and is a directory
- SRC_PATH does not end with /.
- the source directory is copied into this directory
- SRC_PATH does end with /.
- the content of the source directory is copied into this directory
因此,要么 DEST_PATH
不存在,要么存在,您的 docker cp
命令实际上是 docker cp child-dir/ uncle-dir
(带有尾部斜杠)。
假设我有以下目录结构
parent-dir
+ child-dir
+ grandchild-file-a
+ grandchild-file-b
uncle-dir
.
..
现在在 unix 上 - 如果我 运行 命令
parent-dir> cp child-dir ../uncle-dir
那我期望得到
uncle-dir
+ child-dir
+ grandchild-file-a
+ grandchild-file-b
但是如果我用 docker cp
重复这个,我会得到
uncle-dir
+ grandchild-file-a
+ grandchild-file-b
如果我这样做了,这在 unix 上可能是合理的:
parent-dir> cp child-dir/* ../uncle-dir
我的问题是:Docker cp 与 Unix cp 的工作方式不同的原因是什么?
cp
上的 docker 文档解释了这一点:
- SRC_PATH specifies a directory
- DEST_PATH does not exist
- DEST_PATH is created as a directory and the contents of the source directory are copied into this directory
- DEST_PATH exists and is a file
- Error condition: cannot copy a directory to a file
- DEST_PATH exists and is a directory
- SRC_PATH does not end with /.
- the source directory is copied into this directory
- SRC_PATH does end with /.
- the content of the source directory is copied into this directory
因此,要么 DEST_PATH
不存在,要么存在,您的 docker cp
命令实际上是 docker cp child-dir/ uncle-dir
(带有尾部斜杠)。