Skip to content

copy-instead-of-add

Dockerfilesuspiciousno fixdefault: offdockerfile/hadolint

Reports an ADD that only copies. That is an ADD with no URL (http://, https://) and no archive (a name ending in .tar, .gz, .tgz, .xz, .bz2 and the like) among its arguments.

ADD does more than copy: it unpacks local tar archives and downloads URLs. For a plain file or folder that is a surprise, since an archive you meant to copy is extracted and a value that turns out to be a URL starts a download. COPY only copies, so the instruction says what happens.

Keep ADD for unpacking an archive into the image.

Reported
...
COPY a b /dest/
COPY a /dest
ADD app.js /app/
ADD app.tar.gz /app/
ADD https://example.com/f /app/
...
dockerfile:
lint:
rules:
copy-instead-of-add: warn # off (default), warn, error

Enabled by the presets: dockerfile/hadolint.

Suppress one line with sudsy-disable-next-line copy-instead-of-add in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
hadolint DL3020 partial Reports an ADD with no URL and no archive among its arguments; hadolint reports one source that is neither.