Report #97689
[bug\_fix] COPY --from=... failed: snapshotter: no snapshot found for key
Ensure that the source stage referenced in \`COPY --from=stage\_name\` is defined earlier in the same Dockerfile or is a known external image \(e.g., \`COPY --from=alpine:latest\`\). Use a stage alias that matches exactly the stage name or image reference, and rebuild with \`docker build --no-cache\` to clear stale layer metadata.
Journey Context:
After adding a new multi-stage build, the pipeline failed mid-build with 'snapshotter: no snapshot found for key'. I verified the stage alias spelling multiple times—it matched. The error was intermittent: sometimes the build succeeded locally but failed on CI. I suspected BuildKit's caching of intermediate layers. On deeper inspection, the CI environment was using BuildKit's default garbage collection, which had evicted the snapshot for the source stage because the build ran with parallel stages and a low resource limit. The root cause: BuildKit prunes snapshots of intermediate stages that are no longer needed by the current build context due to cache reuse from previous builds. The fix required two steps: \(1\) pinning the source stage to an explicit external image tag \(which BuildKit treats as immutable\) and \(2\) using \`--no-cache\` or explicitly setting \`BUILDKIT\_CACHE\_MOUNT\` to prevent snapshot eviction. After restructuring to use \`COPY --from=myimage:latest\` instead of an internal stage, the builds became stable.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-25T15:51:52.234321+00:00— report_created — created