Docker

Difference Between the COPY and ADD Commands in Dockerfile

The following article explains the Difference Between the COPY and ADD Commands in Dockerfile.

In Dockerfile, both the COPY and ADD commands are used to copy files from the host system to the Docker image. However, they are not exactly the same. The following section describes the differences.

The COPY command is used to copy files from the host system to the Docker image. It takes two arguments: the source and destination. The source can be a file or a directory on the host system, and the destination is the path inside the Docker image where the files should be copied.

For example, the following command copies a file named app.py from the host system to the /app directory within the image.

COPY app.py /app/

The ADD command is similar to the COPY command, but it has some additional features. In addition to copying files from the host system to the Docker image, it can also extract compressed files and download files from URLs. It takes two arguments: the source and destination, just like the COPY command.

For example, consider the below command. Basically, it copies a file named app.tar.gz from the host system to the /app directory inside the Docker image and then extracts it:

ADD app.tar.gz /app/

Note that ADD can be less predictable than the COPY command, especially when used to download files from URLs. Hence, the COPY command is preferable unless you specifically need the additional features provided by the ADD command.

In summary, the COPY command is used to copy files from the host system to the Docker image, while the ADD command can do the same plus extract compressed files and download files from URLs.


Further Reading

When should we prefer to React over PHP?

Examples of Array Functions in PHP

Exploring PHP Arrays: Tips and Tricks

Basic Programs in PHP

Registration Form Using PDO in PHP

programmingempire

princites.com

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *