Dockerfile文件-COPY复制文件到容器
COPY添加文件到容器(基本于ADD没有区别)
COPY
将文件从路径 <src
复制添加到容器内部路径 <dest>
.
<src>
必须是想对于源文件夹的一个文件或目录,也可以是一个远程的url
<dest>
是目标容器中的绝对路径。
所有的新文件和文件夹都会创建UID 和 GID .
事实上如果 <src>
是一个远程文件URL,那么目标文件的权限将会是600。
注意:如果你将一个
Dockerfile
通过 STDIN (docker build - < somefile
)传递给build命令, 这就没有了资源文件,Dockerfile
can only contain a URL basedADD
instruction. 你可以将一个压缩包通过STDIN传递给build: (docker build - < archive.tar.gz
), 文件包会传递到容器的根目录里.Note: 如果你填写的远程URL需要验证,那么使用
RUN wget
,RUN curl
或者其他工具,因为ADD指令是不提供验证的。Note: 当资源内容中的<src>发送改变的时候,ADD指令会将所有的缓存置为失效,同时包括 RUN 指令的缓存
规则:
<src>
必须在build的资源目录中; 不可以使用ADD ../something /something
, 因为docker build
的第一步就需要帮资源目录和子目录发送给 docker daemon.如果
<src>
是一个URL 同时<dest>
不是斜线结尾, 那么文件会被先下载然后复制到<dest>
.If
<src>
is a URL and<dest>
does end with a trailing slash, then the filename is inferred from the URL and the file is downloaded to<dest>/<filename>
. For instance,ADD http://example.com/foobar /
would create the file/foobar
. The URL must have a nontrivial path so that an appropriate filename can be discovered in this case (http://example.com
will not work).如果
<src>
是一个目录,那么这个目录也包括文件系统元数据都会被复制。如果
<src>
是一个常见的压缩包然后解压在一个目录下, Resources from remote URLs are not decompressed. When a directory is copied or unpacked, it has the same behavior astar -x
: the result is the union of:- 无论目标路径是否存在。
- 源代码树中的内容,有冲突的解决有利于“2”。在文件通过文件为基础。
如果源文件是任意文件,都会使用元数据复制,如果目标以斜线结尾,则将文件复制到目录下。
如果
<dest>
不是以斜线结尾的,文件就会以普通文件形式写入到目标。如果
<dest>
不存在, 文件会被创建在默认不存在路径下。