failed to solve: target stage "builder" could not be found
Fixes 'target stage could not be found' in multistage docker builds. Use when docker build --target names a stage that does not exist, usually from a typo or a renamed AS alias. Not for COPY --from failures between existing stages.
TL;DR: The --target name does not match any FROM ... AS [name] in the Dockerfile. List your stage aliases (grep -n "^FROM" Dockerfile) and fix the typo or the renamed stage. Stage names are case-sensitive and must match exactly.
The error
failed to solve: target stage "builder" could not be foundFix it
- List the stages actually defined:
grep -n "^FROM" Dockerfile Expected: lines like FROM node:20 AS build showing the real alias.
- Fix the mismatch, either the build command:
docker build --target build . or the Dockerfile alias: FROM node:20 AS builder
- Rebuild.
When this applies
docker build --target [name]with a misspelled or stale stage name- Dockerfiles refactored to rename stages without updating CI scripts
When this does NOT apply
COPY --from=[name]failing (that names the source stage in the Dockerfile itself; check the alias there)- "failed to read dockerfile" (file missing, earlier failure)
Versions
All BuildKit versions; classic builder says "failed to find stage" variants.
Why it happens
--target selects which stage to build up to. BuildKit resolves the name against the AS aliases parsed from the Dockerfile; anything else is an error, and the message quotes the name you passed so you can diff it against the file.
Edge cases
- Stage names are case-sensitive:
AS Builderis not--target builder. - A stage defined AFTER the target in file order is fine; order does not matter, only the name.
docker buildx baketargets are defined in the bake file, not the Dockerfile; a bake target typo produces a different error.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.