Note ADD can auto-extract tar archives and fetch URLs. However, COPY is preferred for simple file copies because ADD's extra behavior can be surprising. Using ADD for URL downloads also defeats layer caching - use RUN curl instead for better control.
# Use COPY for plain file copies (clear intent):COPY package.json./COPY src/./src/# Only use ADD when you specifically want extraction:ADD assets.tar.gz/app/assets/
Note ADD auto-extracts tar archives and can fetch URLs, which is rarely what you want. COPY does exactly one thing - copies files. Using COPY makes your Dockerfile easier to reason about and avoids accidental extraction of files you wanted to keep as archives.
Frequently asked questions
How do you copy vs add?
Docker covers this with 2 copy-ready snippets on this page. The "ADD - Copy with Extras" snippet in Docker uses `ADD <src> <dest>`.
Which command does the Docker example use?
The "ADD - Copy with Extras" snippet uses `ADD <src> <dest>`, from the Dockerfile section of the Docker cheat sheet.
What other Docker snippets are shown for "copy vs add"?
Besides "ADD - Copy with Extras", this page also shows "Using ADD When You Mean COPY".
Is there anything to watch out for?
Yes. For "ADD - Copy with Extras": ADD can auto-extract tar archives and fetch URLs. However, COPY is preferred for simple file copies because ADD's extra behavior can be surprising. Using ADD for URL downloads also defeats layer caching - use RUN curl instead for better control.