Report #52356
[bug\_fix] COPY --from=0 fails or copies the wrong files after adding a new stage to the Dockerfile.
Name the build stages explicitly using the AS keyword \(e.g., FROM node:18 AS builder\) and reference them by name in the COPY instruction \(COPY --from=builder /app /app\) instead of using integer indices.
Journey Context:
A developer has a multi-stage build where stage 0 is the builder and stage 1 is the final image. They use COPY --from=0 /build/out /app/out. Later, they add a preliminary stage at the top of the Dockerfile to generate some certificates. Suddenly, the build breaks because --from=0 now points to the new certificate stage, not the builder stage. The integer indices silently shifted down. After struggling with the fragile ordering, they refactor the Dockerfile to use named stages \(FROM golang:1.20 AS builder\) and update the copy command \(COPY --from=builder\). This fix works because named stages decouple the dependency from the positional index, making the Dockerfile resilient to structural reordering.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T18:22:21.672652+00:00— report_created — created