Docker "stage name not found" multi-stage build error in CI
A COPY --from=<name> (or FROM <name>) must reference a stage that was already declared with FROM ... AS <name> earlier in the file. A misspelled name, or a stage defined later, leaves BuildKit with no such stage to copy from.
What this error means
A build fails with an invalid --from flag or unknown stage error at a COPY --from=. The referenced stage name does not match any earlier AS declaration.
docker
ERROR: failed to solve: invalid from flag value builder: stage "builder" could not be found
# from: COPY --from=builder /app/bin /app/binCommon causes
A misspelled stage name
The AS build declaration and the --from=builder reference do not match.
The stage is declared after the COPY
Stages must be defined before they are referenced; a later FROM ... AS x is not visible to an earlier COPY.
How to fix it
Match the stage name exactly
- Use the same identifier in
ASand--from. - Keep stage names lowercase and consistent.
Dockerfile
FROM golang AS build
RUN go build -o /app/bin ./...
FROM alpine
COPY --from=build /app/bin /app/binDeclare the stage before referencing it
- Order stages so any referenced stage appears earlier in the file.
Dockerfile
FROM node AS deps
# ...
FROM node AS app
COPY --from=deps /node_modules ./node_modulesHow to prevent it
- Keep AS names and --from references identical.
- Declare stages before any reference to them.
- Lint multi-stage Dockerfiles with hadolint.
Related guides
Docker "COPY --from" Stage Index/Name Does Not Exist in CIFix Docker "COPY --from=<x>: invalid from flag value" / stage not found in CI - a COPY --from referencing a s…
Docker "target stage could not be found" - Fix Multi-Stage BuildsFix Docker "failed to solve: target stage X could not be found" in CI - a --target or COPY --from naming a bu…
Docker "failed to compute cache key: ... not found COPY --from" in CIFix BuildKit "failed to compute cache key: ... not found" on a COPY --from in CI - the file or path being cop…