问题描述
Dockerfile中的 COPY
和 ADD
命令之间有什么区别,何时使用
What is the difference between the COPY
and ADD
commands in a Dockerfile, and when would I use one over the other?
COPY <src> <dest>
ADD <src> <dest>
推荐答案
您应检查和文档以更详细地描述其行为,但简而言之,主要区别在于 ADD
可以完成 COPY
:
You should check the ADD
and COPY
documentation for a more detailed description of their behaviors, but in a nutshell, the major difference is that ADD
can do more than COPY
:
-
ADD
允许< src>
作为URL - 请参阅下面的注释,
ADD
指出:
ADD
allows<src>
to be a URL- Referring to comments below, the
ADD
documentation states that:
请注意,建议使用 COPY
,其中<$ c不需要$ c> ADD 。否则,有一天(当您打算将 keep_this_archive_intact.tar.gz
复制到其中时,您(因为您必须查找此答案),您可能会感到惊讶。您的容器,而是将内容喷到文件系统上。
Note that the Best practices for writing Dockerfiles suggests using COPY
where the magic of ADD
is not required. Otherwise, you (since you had to look up 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.
这篇关于Dockerfile中的“ COPY”和“ ADD”命令有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!