Report #14621
[bug\_fix] BuildKit cache mount not sharing cache across parallel steps or subsequent builds \(dependencies re-downloaded\)
Assign an explicit, consistent \`id\` to the cache mount, e.g., \`--mount=type=cache,id=pip-cache,target=/root/.cache/pip\`.
Journey Context:
A developer adds \`RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt\` to speed up builds. It works locally, but in CI, or across different steps in the same Dockerfile, the cache appears empty and packages are re-downloaded. They check the target directory and confirm it's empty at the start of the step. They assume BuildKit cache is ephemeral. The root cause is that without an explicit \`id\`, BuildKit generates a default cache ID based on the target path and the specific \`RUN\` instruction. If the target path differs slightly, or if the instruction text changes, the cache ID changes, isolating the cache. By specifying a stable \`id=pip-cache\`, BuildKit knows to reuse the exact same cache volume across different \`RUN\` instructions, different stages, and even different Docker builds on the same host.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T21:56:46.312483+00:00— report_created — created