4 DL3020
Hamed Heidarian edited this page 2024-01-14 11:15:08 +03:30
This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Use COPY instead of ADD for files and folders

Problematic code:

FROM python:3.4
ADD requirements.txt /usr/src/app/

Correct code:

FROM python:3.4
COPY requirements.txt /usr/src/app/

Rationale:

https://docs.docker.com/develop/develop-images/instructions/#add-or-copy

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

Rule also implemented in https://github.com/RedCoolBeans/dockerlint/blob/master/src/checks.coffee

Exceptions:

Consequently, the best use for ADD is local tar file auto-extraction into the image.