When to use ADD or COPY to copy files to a Dockerfile?

Asked

Viewed 2,399 times

2

Dockerfile syntax has two instructions for copying files: ADDand COPY. Both copy files to the container. When to use each?

1 answer

2


The application will depend on what you are trying to transfer to the container. According to this answer on SOen, the largest difference in the method ADD to the COPY is:

  • Method ADD allows the attribute SRC be a URL
  • If the file entered in the attribute SRC of the method ADD have a recognized compression format, it will be uncompressed.

There is a documentation of the Docker: ADD or COPY where it informs the same thing, and that it is preferable to use the method COPY for being transparant.

That is, if you will not use the remote transfer and decompression feature, use the method COPY.

  • 1

    Complementing: the official documentation indicates that the ADD is not specified to fetch remote packages because it increases the image size. The given is to get with RUN curl or similar and unpack with taror similar, then removing the original package.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.