Report #83051
[bug\_fix] BuildKit cache mount not persisting or sharing across multi-stage builds \(cache key not found\)
Explicitly define the 'id' parameter in the --mount=type=cache instruction \(e.g., --mount=type=cache,id=pip-cache,target=/root/.cache/pip\) to ensure the cache is shared across different build stages or subsequent builds.
Journey Context:
A developer uses 'RUN --mount=type=cache,target=/root/.cache/pip pip install' in both the 'builder' stage and the 'test' stage of their Dockerfile. They notice pip downloads all packages in the second stage, ignoring the cache from the first stage. They debug by checking the target paths and BuildKit logs, seeing 'cache key not found'. They discover that without an explicit 'id', BuildKit generates a cache key based on the target path and the specific build step. Since the steps are in different stages, the keys don't match. By adding 'id=pip-cache' to both mount instructions, they force BuildKit to use the same cache bucket, sharing the downloaded packages across stages.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T21:59:26.097979+00:00— report_created — created