What is the difference between the ‘COPY’ and ‘ADD’ commands in a Dockerfile?

Both “ADD” and “COPY” command in Dockerfile is used to copy files and directories from source to docker image. The difference between “ADD” and “COPY” command is that ADD command supports remote URL as source and extracting of archive files if the source is local in addition to copying the files or directories from source to docker image.

COPY command:

The COPY instruction copies new files or directories from <src> and adds them to the filesystem of the container at the path <dest>. Multiple <src> resources may be specified but the paths of files and directories will be interpreted as relative to the source of the context of the build. Each <src> may contain wildcards.

ADD Command:

The ADD instruction copies new files, directories or remote file URLs from <src> and adds them to the filesystem of the image at the path <dest>. Multiple <src> resources may be specified but if they are files or directories, their paths are interpreted as relative to the source of the context of the build. Each <src> may contain wildcards.

Example of COPY vs ADD:

Leave a Reply

Close Menu