Docker Dockerfile COPY vs ADD

http://blog.163.com/digoal@126/blog/static/163877040201410341236664/
 
在Dockerfile中, 我们可以使用ADD和COPY拷贝文件(注意是上下文相关目录的文件, 不是本地的任意文件, 除非上下文目录是根)到container制作image.
那么两者有什么区别呢?
 
ADD 多了2个功能, 下载URL和解压.  其他都一样.
如果你不希望压缩文件拷贝到container后会被解压的话, 那么使用COPY.
如果需要自动下载URL并拷贝到container的话, 请使用ADD.
 
  • If <src> is a URL and <dest> does not end with a trailing slash, then a file is downloaded from the URL and copied to <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).

  • If <src> is a local tar archive in a recognized compression format (identity, gzip, bzip2 or xz) then it is unpacked as a directory. Resources from remote URLs are not decompressed. When a directory is copied or unpacked, it has the same behavior as tar -x: the result is the union of:

    1. Whatever existed at the destination path and
    2. The contents of the source tree, with conflicts resolved in favor of "2." on a file-by-file basis.
[参考]
原文地址:https://www.cnblogs.com/shiningrise/p/5737241.html