and are both instructions that serve similar purposes. They let you copy files from a specific location into a Docker image.

COPY

The instruction copies new files or directories from and adds them to the filesystem of the container at the path .

COPY has two forms:

  • (this form is required for paths containing whitespace)

ADD

ADD has two forms:

  • (this form is required for paths containing whitespace)

Dockerfile best practice for copying from a URL

Docker suggests that it is often not efficient to copy from a URL using , and it is best practice to use other strategies to include the required remote files.

only supports the basic copying of local files into the container, while has some features (like local-only tar extraction and remote URL support) that are not immediately obvious. Consequently, the best use for is local tar file auto-extraction into the image, as in .

Because image size matters, using to fetch packages from remote URLs is strongly discouraged; you should use or instead. That way you can delete the files you no longer need after they’ve been extracted and you don’t have to add another layer in your image. For example, you should avoid doing things like:

— Dockerfile Best Practices

And instead, do something like:

For other items (files, directories) that do not require ’s tar auto-extraction capability, you should always use .

Like to learn?

Follow me on twitter where I post all about the latest and greatest AI, DevOps, VR/AR, Technology, and Science! Connect with me on LinkedIn too!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store