Skip to content

copy-from-own-stage

Dockerfilecorrectnessno fixdefault: errordockerfile/hadolint

Reports a COPY --from that names its own stage. That is COPY --from=build in the stage that FROM alpine AS build starts. Names are compared without regard to case.

A stage cannot copy from itself: its content does not exist yet while it is built, and BuildKit stops with a circular dependency error. The source is usually an earlier stage, or the build context (then drop --from).

Reported
...
FROM alpine:3 AS last
COPY --from=LAST /a /b
USER app
CMD ["a"]
...
dockerfile:
lint:
rules:
copy-from-own-stage: error # off, warn, error (default)

Enabled by the presets: dockerfile/hadolint.

Suppress one line with sudsy-disable-next-line copy-from-own-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 DL3023 full