cancel
Showing results for 
Search instead for 
Did you mean: 
Moonorb1
Cadet
Cadet
  • 1,121 Views

ADD vs COPY

Hi, 

EX180 exam has 2 objectives as follows: 

  • Understand and use ADD instruction.
  • Understand and use COPY instruction.

I am trying to understand when to use which one... Since ADD has more capability then COPY such as supporting copying from URL and/or the archive functionality, what would be the use case to prefer COPY over ADD when we can just simply use ADD. In other words why do we have COPY when we can use ADD?

 

thanx.  

Labels (1)
2 Replies
Marek_Czernek
Flight Engineer Flight Engineer
Flight Engineer
  • 1,008 Views

In general, I would recommend you use COPY whenever applicable, and only use ADD when you explicitly need one of its additional use cases.

Typically with ADD, you'll still need to do some cleanup, like deleting downloaded resources, in which case you might as well download the resource with the RUN instruction and chain the commands.

Using ADD by default means that developers might encounter unexpected behavior, such as adding tar file and noticing that it's actually expanded when that wasn't the intent.

Explicit is always better than implicit, which is why I would recommend using COPY instead of ADD when applicable. This is recommended by Docker as well.

HTH,
M.

Moonorb1
Cadet
Cadet
  • 992 Views

Thank you Marek

0 Kudos
Join the discussion
You must log in to join this conversation.