What Is the Difference between the ‘COPY’ and ‘ADD’ Commands in a Dockerfile?
When creating a Docker file, you may need to transfer some files from the host system to the docker image. Those files may be for example libraries or any other files that your application may need at runtime.
To do that, docker provides two commands - COPY
and ADD
What is the difference?
Both COPY
and ADD
commands allow you to add files to your docker image from a specific location. Both of these commands take to arguments <src>
(location of the source file) and <dest>
(copy destination).
In the case of the COPY
command, it only allows you to copy files from the local machine (the machine creating the Docker image).
Whereas ADD
command allows the source path to be a URL address. It can also extract tar files from the source to the destination.
Which one should you use?
It is a best practice to always prefer COPY
over ADD
unless you especially need one of the additional features of ADD
. As mentioned above, ADD
command automatically expands which can lead to unexpected wiles being written to the docker image.
-
What Is the Difference between Docker-Compose Ports and Expose?
You may have wondered what is the difference between docker-compose ports and docker-compose expose. Here is a clear explanation to help you better understand the matter. Ports Ports mentioned in t...
Questions -
How Do I Pass Environment Variables to Docker Containers?
It is always a good practice to separate the app from its configuration. It is not a good idea to have a database login credential defined as variables in the code of the application. This is why w...
Questions -
Solved: Cron missing newline before EOF
This error may also happen when a crontab file is generated automatically and the generator failed to insert a newline character at the end of the crontab file.
Questions -
How to Connect to the Localhost of the Machine from inside of a Docker Container?
If you are running some kind of a server or any other service (such as a database) on localhost and the service isn’t exposing any port, you may have found yourself wondering how to connect to this...
Questions
We are hiring.
Software is our way of making the world a tiny bit better. We build tools for the makers of tomorrow.
Help us in making the internet more reliable.

Help us with developer education and get paid.
