×
☰ See All Chapters

Docker COPY vs ADD command

The docker ADD and COPY both commands can be used to copy the files or directories from the Docker host to the image file system. The ADD instruction is similar to the COPY instruction. However, in addition to the functionality supported by the COPY instruction, the ADD instruction can handle the TAR files and the remote URLs. If source is given with TAR files either from file system or from remote URLs, ADD command will not just copy that TAR file but automatically uploads, uncompresses, and puts the resulting folders and files of TAR file at the destination. If you source is a TAR file for a COPY command, COPY command just copy that TAR file to destination, it will not uncompress and extract the files from it.

COPY

ADD

Does not support remote URLs for source

Support remote URLs for source

If TAR file is the source, COPY command just copy that file.

If TAR file is the source, ADD command extract the contents of TAR file to destination.

Examples

ADD sources/config.xml app.xml        

# Copy file config.xml and rename it to app.xml

ADD sources /sources/

# Copy all contents from sources directory to sources directory in image

ADD sources/deploy.tar.gz /sources/

# Extract all contents from sources/deploy.tar.gz file to sources directory in image

ADD https://www.java4coding.com/deploy.tar.gz /sources/

# Download the deploy.tar.gz from https://www.java4coding.com/ and extract the contents of deploy.tar.gz to sources directory in image

COPY sources/config.xml app.xml        

# Copy file config.xml and rename it to app.xml

COPY sources /sources/

# Copy all contents from sources directory to sources directory in image

 

 


All Chapters
Author