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 -
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 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 -
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
Make your mark
Join the writer's program
Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.
Write for usBuild on top of Better Stack
Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.
community@betterstack.comor submit a pull request and help us build better products for everyone.
See the full list of amazing projects on github