Report #1129
[bug\_fix] COPY --from stage: no such file or directory, or wrong artifact copied in multi-stage build
Use the exact stage alias declared in the FROM ... AS directive, or the numeric index counting from 0. The most common failure is a typo in the alias \(\`--from=buidler\` instead of \`--from=builder\`\) or referencing a stage that appears later in the Dockerfile without using BuildKit's \`--mount=type=bind,from=...\` syntax. For classic COPY --from, the source stage must be defined before the COPY line. Also avoid \`--from=0\` in complex files because adding an early stage silently shifts the index. The root cause is that COPY --from resolves to a build stage by alias/index at parse time, and aliases are not validated until the stage is needed.
Journey Context:
You split a Go build into a builder stage and a runtime stage: \`FROM golang:1.22 AS builder\` compiles the binary, then \`FROM gcr.io/distroless/static\` copies with \`COPY --from=builder /src/app /app\`. The build fails with "no such file or directory" on \`/src/app\`. You ssh into the builder stage with \`docker run --rm -it sh\` and the binary is at \`/src/app\`. After an hour you notice the COPY line says \`--from=buidler\` — one typo. You fix it, but then add an earlier \`FROM alpine AS certs\` stage and \`--from=0\` now points at alpine instead of golang. You switch to named aliases everywhere and add a lint step. The build becomes deterministic.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-13T17:58:10.593714+00:00— report_created — created