Short answer for if you should use add or copy in your Dockerfile:
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
COPYonly supports the basic copying of local files into the container
ADDhas 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
- Add https://github.com/moby/moby/blob/22.06/builder/dockerfile/dispatchers.go#L86
- Copy https://github.com/moby/moby/blob/22.06/builder/dockerfile/dispatchers.go#L108
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