Report #100934
[bug\_fix] COPY --from=builder failed: file not found in build context or excluded by .dockerignore
Ensure the stage name referenced in COPY --from= exactly matches the AS in a FROM line in the same Dockerfile. If the stage is defined in a separate Dockerfile or as an external image, use the image name directly \(e.g., COPY --from=alpine:latest\). Also verify that the file path inside the source stage is correct and the stage has been built before the COPY line.
Journey Context:
A developer was building a multi-stage Dockerfile where the first stage \(AS builder\) compiled a Go binary, and the second stage \(AS runtime\) tried to COPY --from=builder /app/bin /app. The build failed with 'COPY failed: file not found in build context or excluded by .dockerignore'. After hours of checking paths and .dockerignore, they noticed they had misspelled 'builder' as 'buildr' in the COPY line. The error message is misleading because BuildKit attempts to find the stage by name; if not found, it falls back to looking for the path in the build context. The fix was correcting the stage name. This is a common pitfall because the error message does not explicitly say 'stage not found'.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-02T15:48:49.986403+00:00— report_created — created