Member-only story

Docker COPY vs ADD

Park Sehun
3 min readAug 9, 2023

In Docker, both the COPY and ADD commands are used to copy files and directories from the host system into a Docker image. While both commands support similar functions, COPY takes local files or directory from your host and ADD can do more like

  • Use URL instead of a local file / directory
  • Extract a tar file from the source directly into the destination.

Difference

  1. Source and destination: The COPY command takes two parameters: the source path on the host and the destination path in the image. The ADD command also takes the same parameters, but it allows additional features like URL support and automatic extraction of compressed files.
  2. URL support: The ADD command supports copying files directly from URLs, whereas the COPY command does not. With ADD, you can specify a URL as the source, and Docker will download the file and copy it into the image. This can be useful for downloading external resources during the image build process.
  3. Automatic extraction: The ADD command has the ability to automatically extract compressed files (e.g., tar, gzip, and zip) during the copy operation. If the source file is a compressed archive, ADD will automatically extract it to the destination path in the image. On the other hand, the COPY command copies the file as-is without any extraction.
  4. Cache invalidation: When using the COPY command, Docker can utilize the build cache to speed up subsequent builds. If the source files have not…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

No responses yet

Write a response