Docker Should I use add or copy Dockerfile?

Short answer for if you should use add or copy in your Dockerfile:

Use: Copy

Longer answer, go through the documentation add-or-copy and figure out if you need the functionality the ‘add’ command gives you. But the essence is that Add can do more than Copy

  • COPY only supports the basic copying of local files into the container
  • ADD has some features (like local-only tar extraction and remote URL support) that are not immediately obvious
COPY requirements.txt /tmp/
RUN pip install --requirement /tmp/requirements.txt
COPY . /tmp/

To see the really cool part and under the hood. Here’s the source code for Copy and Add

Here’s the documentations for the add function. Stating tarball and remote url handling.

// ADD foo /path
//
// Add the file 'foo' to '/path'. Tarball and Remote URL (http, https) handling
// exist here. If you do not wish to have this automatic handling, use COPY.

And for copy it clearly states it’s the same as the add command but without tar and remote url handling.

// COPY foo /path
//
// Same as 'ADD' but without the tar and remote url handling.

The project is here for docker and dockerfile https://github.com/moby/moby/tree/master