Report #94931
[bug\_fix] COPY --from=0 fails or copies wrong artifacts after adding a new build stage
Stop using integer indices for stages \(e.g., --from=0\). Name the build stages using AS \(e.g., FROM node:18 AS builder\) and reference them by name \(COPY --from=builder /app/dist /dist\).
Journey Context:
A developer has a multi-stage Dockerfile with three stages, using COPY --from=0 and COPY --from=1. It works perfectly. Later, they add a preliminary stage at the top for security scanning. Suddenly, the final image is broken or missing files. The error messages are cryptic, just complaining about missing files in the destination. They spend hours checking the build logs, not realizing that adding a stage at the top shifted all the integer indices: the old stage 0 is now stage 1. The fix is to refactor the Dockerfile to use named stages. Named stages are resilient to reordering, making COPY --from=builder deterministic and saving future debugging time.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T17:55:24.769524+00:00— report_created — created