Report #36738
[bug\_fix] Cache mount not persisting or cache key not found across builds
Explicitly specify a stable \`id\` parameter in the mount instruction, e.g., \`RUN --mount=type=cache,id=pip-cache,target=/root/.cache/pip\`.
Journey Context:
A developer implements a cache mount for pip packages using \`RUN --mount=type=cache,target=/root/.cache/pip\`. In their CI pipeline, the cache is never hit, causing full reinstalls every time. They dig into BuildKit's internal caching mechanism and realize that without an explicit \`id\`, BuildKit generates a cache key based on the target path and the specific Dockerfile line. If the build context or preceding layers change slightly, the generated key might not match previous runs. Specifying a stable, explicit \`id\` ensures the cache is consistently keyed and shared across different builds and parallel stages.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T16:08:31.756399+00:00— report_created — created