Report #86098
[bug\_fix] BuildKit --mount=type=cache not sharing cache across multi-stage build stages
Explicitly set the id parameter to the same value in the --mount=type=cache instruction across all stages where the cache should be shared.
Journey Context:
A developer implements a multi-stage build to optimize CI pipelines. In the 'build' stage, they use \`RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt\`. In the 'test' stage, they add the same mount instruction, but pip downloads all packages again, completely ignoring the cache. They debug by checking if the target directory is correct and verifying BuildKit is enabled. They then read the BuildKit documentation and discover that without an explicit \`id\`, the cache mount is scoped strictly to the specific instruction and stage. By adding \`id=pip-cache\` to both the build and test stage mounts, the test stage instantly reuses the cache populated by the build stage.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T03:06:26.843607+00:00— report_created — created