Report #9945
[bug\_fix] ERROR: failed to solve: failed to compute cache key: stage not found, or copying the wrong bloated artifacts instead of the compiled binary
Explicitly name build stages using the AS keyword \(e.g., FROM golang:1.20 AS builder\) and reference them by name in COPY --from=builder instead of using integer indices.
Journey Context:
A developer has a multi-stage Dockerfile where Stage 0 builds a frontend and Stage 1 builds a backend. They use COPY --from=0 and COPY --from=1. Later, they add a linting stage at the top of the Dockerfile, shifting all subsequent indices down by one. The build either fails with 'stage not found' or, worse, silently copies the frontend artifacts into the backend image, creating a massive, broken image. The root cause is relying on ephemeral integer indices that break when the Dockerfile structure changes. The fix is to use named stages \(FROM node:18 AS frontend-build\) and reference them explicitly \(COPY --from=frontend-build\), making the build resilient to reordering and self-documenting.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T09:24:45.246760+00:00— report_created — created