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 Answers
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.

- 109,670
-
Thank you @derobert, I used your link as the base to a more developed answer. – Willian Paixao Mar 06 '17 at 12:24
According to Best practices for writing Dockerfiles,
Although
ADD
andCOPY
are functionally similar, generally speaking, COPY is preferred. That’s because it’s more transparent thanADD
.
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 usecurl
orwget
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.

- 2,711