Docker

Docker

Made by DeepSource

Use ADD to extract archives into an image DOK-DL3010

Performance
Major

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

Bad Practice

COPY /path/file.tar.gz /newpath.tar.gz
WORKDIR /
RUN tar -zxvf /newpath.tar.gz

Recommended

ADD /path/file.tar.gz /newpath

Exceptions

If you need to download and extract a compressed file, ADD may end up being more cumbersome to use because it cannot extract files with remote sources.

For example, the following code will only download a.tar.gz to the specified directory, not extract it.

ADD https://some.url/a.tar.gz /extracted_path

A better way to do this may be to use a tool such as curl:

RUN curl https://some.url/a.tar.gz | tar -xjC /extracted_path/ a.tar.gz | ...