Report #52733
[bug\_fix] BuildKit cache mount does not persist dependencies across multi-stage builds
Specify an explicit \`id\` in the \`--mount=type=cache\` directive \(e.g., \`--mount=type=cache,id=pip-cache,target=/root/.cache/pip\`\) to share the cache volume across different stages and RUN instructions.
Journey Context:
A developer configures a multi-stage Dockerfile using BuildKit's \`--mount=type=cache,target=/root/.cache/pip\` to speed up \`pip install\` in both the 'build' and 'test' stages. They notice that while the cache works within the 'build' stage, the 'test' stage completely re-downloads all packages. They initially suspect Docker layer caching issues or BuildKit cache invalidation. After digging into BuildKit documentation, they realize that without an explicit \`id\`, BuildKit generates a unique cache ID based on the target path and the specific stage/instruction. By adding a shared \`id=pip-cache\` to the mount options in both stages, BuildKit uses the same cache volume, instantly resolving the redundant downloads.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T19:00:31.756859+00:00— report_created — created