Skip to content

copy-from-unknown-stage

Dockerfilecorrectnessno fixdefault: warndockerfile/hadolint

Reports a COPY --from=name that names no stage defined earlier. Not reported: the number of an earlier stage (--from=0) and an image reference with a : (--from=nginx:1). A stage defined further down does not count. Names are compared without regard to case.

Docker does not fail on an unknown name: it takes it for an image and pulls it from the registry. A typo in a stage name (buidler) or a reference to a stage defined further down copies files from whatever image has that name, or fails only when the pull fails.

Reported
...
USER app
...
COPY --from=build /a /b
COPY --from=nope /a /b
COPY --from=BUILD /a /b
COPY --from=0 /a /b
COPY --from=99 /a /b
COPY --from=alpine:3 /a /b
CMD ["a"]
...
dockerfile:
lint:
rules:
copy-from-unknown-stage: warn # off, warn (default), error

Enabled by the presets: dockerfile/hadolint.

Suppress one line with sudsy-disable-next-line copy-from-unknown-stage in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
hadolint DL3022 full