You should check the ADD
and COPY
documentation for an exhaustive description of their behaviours, but in a nutshell the major difference is that ADD
can do more than COPY
:
(您应该查看ADD
和COPY
文档以获得有关其行为的详尽描述,但简而言之,主要区别在于ADD
可以做的不仅仅是COPY
:)
-
ADD
allows <src>
to be a URL (ADD
允许<src>
成为URL)
- Referring to comments bellow, the
ADD
documentation clearly states that: (参考下面的评论, ADD
文件明确指出:)
If is a local tar archive in a recognized compression format (identity, gzip, bzip2 or xz) then it is unpacked as a directory.
(如果是以识别的压缩格式(identity,gzip,bzip2或xz)的本地tar存档,则将其解压缩为目录。)
Resources from remote URLs are not decompressed. (远程URL中的资源不会被解压缩。)
Note that the Best practices for writing Dockerfiles suggests using COPY
where the magic of ADD
is not required.
(请注意, 编写Dockerfiles的最佳实践建议使用COPY
,其中不需要ADD
的魔力。)
Otherwise you (since you had to lookup this answer) are likely to get surprised someday when you mean to copy keep_this_archive_intact.tar.gz
into your container, but instead you spray the contents onto your filesystem. (否则你(因为你必须查找这个答案)有一天你可能会感到惊讶,因为你的意思是将keep_this_archive_intact.tar.gz
复制到你的容器中,而是将内容喷到你的文件系统上。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…