COPY vs. ADD

Difficulty: Beginner

Question

When should you use ADD instead of COPY in a Dockerfile?

Answer

Generally, **always use COPY**. It is more transparent and only supports the basic copying of local files into the container.

Use **ADD** only when you need its extra features: 1. Downloading files from a URL. 2. Automatically extracting local tarballs/archives into the image.

Code examples

Examples

# Standard usage
COPY app.js /app/

# Specific ADD usage (extracting)
ADD source.tar.gz /app/

ADD will detect the .tar.gz and extract its contents automatically.

Key points

Concepts covered

Dockerfile, Filesystem