DockerFile:ADD和COPY之间的区别

时间:2016-02-10 10:38:15

标签: docker

根据以下参考资料https://docs.docker.com/engine/reference/builder/#copy 我认为ADD和COPY没有区别。 请帮我一个解释差异的简单例子。

2 个答案:

答案 0 :(得分:15)

在这里找到答案:Docker COPY vs ADD

  • ADD允许<src>成为网址
  • 如果ADD的<src>参数是
    以可识别的压缩格式存档,它将被解压缩

答案 1 :(得分:1)

来自 Docker 在线文档:

ADD or COPY

Although ADD and COPY are functionally similar, generally speaking, COPY is preferred. That’s because it’s more transparent than ADD. COPY only supports the basic copying of local files into the container, while ADD has some features (like local-only tar extraction and remote URL support) that are not immediately obvious. Consequently, the best use for ADD is local tar file auto-extraction into the image, as in ADD rootfs.tar.xz /.

可在 Best Practices for writing Dockerfiles

找到更多信息

基本上,

使用 COPY 进行纯文件和/或目录复制,

使用 ADD 提取 TAR 存档或下载远程内容,