difference between the `COPY` and `ADD` commands in a Dockerfile

0 votes

When do I use Copy command and Add command? Can anyone explain me this?


COPY <src> <dest>

The COPY instruction will copy new files from <src> and add them to the container's filesystem at path <dest>


ADD <src> <dest>

The ADD instruction will copy new files from <src> and add them to the container's filesystem at path <dest>.

Aug 24, 2018 in DevOps & Agile by Damon Salvatore
• 5,510 points
472 views

1 answer to this question.

0 votes

Here is what you can do. Just check the ADD and COPY documentation for an clear description, but in short, the major difference is that ADD can do more than COPY:

  • ADD allows <src> to be a URL
  • If the <src> parameter of ADD is an archive in a recognised compression format, it will be unpacked

Note that the Best practices for writing Dockerfiles suggests using COPY where the magic of ADD is not required. Otherwise you (since you had to lookup this answer) are likely to get surprised someday when you mean to copy keep_this_archive_intact.tar.gz into your container, but instead you spray the contents onto your file system.

I hope it would resolve your query.

Thanks

answered Aug 24, 2018 by Damon Salvatore
• 5,510 points

I would like to add more point over this : 

1) ADD will creates a non existing directory where as COPY won't  do it.

2) I have read some where that if you use URL as a src in ADD with tar file as a download link, you won't get extracted tar file in the destination(I have not checked it)

https://stackoverflow.com/questions/24958140/what-is-the-difference-between-the-copy-and-add-commands-in-a-dockerfile

Thank you @Saurav! Can you make your comment an answer? It'll be easier for other readers to understand.

Related Questions In DevOps & Agile

+2 votes
1 answer

What is the difference between a container and an image in Docker?

 Below is reference which you can follow to know ...READ MORE

answered Sep 20, 2018 in DevOps & Agile by shubham
• 6,890 points
60 views
0 votes
1 answer

How can a script identify the difference between Docker Toolbox and Docker for Windows?

Now, the Toolbox works through docker-machine. The way ...READ MORE

answered Aug 24, 2018 in DevOps & Agile by Tyrion anex
• 8,270 points
64 views
+13 votes
2 answers
0 votes
1 answer

Is there any difference between jenkins ssh publishers and ansible?

In a Layman’s language they're the same ...READ MORE

answered Apr 9, 2018 in DevOps & Agile by shubham
• 6,890 points
180 views
0 votes
1 answer
0 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 56,900 points
193 views
0 votes
1 answer
0 votes
1 answer