Docker ADD vs COPY instructions
December 02, 2024
Edit on GithubWhile reviewing a change in Cookiecutter Django, a co-maintainer (Fábio C. Barrionuevo da Luz @luzfcb) pointed at a section of the Docker documentation outlining the subtle, but important, differences between ADD
and COPY
.
If you asked me yesterday, I wouldn’t have been able to tell you the difference, and this was indeed enlightening. My takeaways:
- Start with
COPY
to copy files into the container, being from the host filesystem or from another stage. - If the file is only needed temporarily, use a
RUN
instruction with bind mount instead. - Use
ADD
if you need to put files into your container from a remote source.
I don’t expect to remember this in one month time, but hopefully this page will help me find the resource quickly next time I need it.