5

Isn't clear to me, why there are two instructions for copying files into the Docker image described in the Dockerfile reference. There are ADD and COPY and they seem pretty similar to me. Is there a practical difference between them? If not, which one is most used?

2 Answers2

6

ADD performs a lot more “magic”: it fetches URLs and unpacks archives. That can be somewhat unexpected (especially the archive unpack). The official best practices guide recommends you use COPY unless you need ADD's extra features.

derobert
  • 109,670
5

According to Best practices for writing Dockerfiles,

Although ADD and COPY are functionally similar, generally speaking, COPY is preferred. That’s because it’s more transparent than ADD.

ADD can extract tar files and fetch remote URL files, although it's not very clear in the official documentation. It's also important to state that,

Because image size matters, using ADD to fetch packages from remote URLs is strongly discouraged; you should use curl or wget instead.

COPY entrypoint.sh /srv/app/
ADD app.tar /srv/app/

So the general rule is as @derobert mentioned, use COPY unless you need ADD exclusive features.