Report #42304
[bug\_fix] COPY failed: no source files were found in the build stage \(Multi-stage build\)
Use named stages \(e.g., FROM node:20 AS builder\) and reference them in COPY --from=builder instead of using integer indices like COPY --from=0.
Journey Context:
A developer sets up a multi-stage build with two stages. In the final stage, they use COPY --from=0 /build/output /app/. It works perfectly. A week later, they add a new preliminary stage at the top of the Dockerfile to handle dependency compilation. Suddenly, the final stage fails with 'no source files found'. They realize the integer index 0 now points to the new preliminary stage, which doesn't have the /build/output directory. Refactoring to use named stages \(FROM node:20 AS builder and COPY --from=builder\) fixes the issue permanently because Docker resolves the string alias regardless of the stage's position in the Dockerfile, making the build resilient to reordering.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T01:28:39.301216+00:00— report_created — created