The subtle differences between the docker ADD and COPY commands


This weekend I spent some time cleaning up a number of Dockerfiles and getting them integrated into my build system. Docker provides the ADD and COPY commands to take the contents from a given source and copy them into your container. On the surface both commands appear to do the same thing but there is one slight difference. The COPY command works solely on files and directories:

The ADD instruction copies new files, directories or remote file URLs from and adds them to the file system of the image at the path .

While the ADD commands supports files, directories AND remote URLs:

The ADD instruction copies new files, directories or remote file URLs from and adds them to the files ystem of the image at the path .

The additional feature provided by ADD allows you to retrieve remote resources and stash them in your container for use by your applications:

ADD http://prefetch.net/path/to/stuff /stuff

Some of the Dockerfiles I’ve read through on github have done some extremely interesting things with ADD and remote resource retrieval. Noting this here for future reference.

This article was posted by Matty on 2017-09-24 08:48:00 -0400 EDT