Report #99134
[bug\_fix] BuildKit \`RUN --mount=type=cache\` reuses stale state even with \`--no-cache\`
Understand that \`--no-cache\` clears layer and inline cache, but not persistent \`RUN --mount=type=cache\` volumes. Prune the specific cache with \`docker buildx prune\` or \`docker builder prune\`, or pin the cache mount \`id=\` and \`sharing=\` correctly. If the cached data itself is corrupt, add a cache-busting step inside the RUN or temporarily remove the mount to force regeneration.
Journey Context:
A team uses \`RUN --mount=type=cache,target=/root/.npm npm ci\` to speed up CI. After a registry incident, npm metadata becomes corrupt. They run \`docker build --no-cache\`, expecting a clean build, but the install still fails with the same stale metadata error. They inspect the BuildKit cache with \`docker buildx du\` and see a large \`exec.cachemount\` entry. They realize \`--no-cache\` only disables the layer cache, not the persistent BuildKit cache mount. After running \`docker builder prune\`, the next build downloads fresh packages and succeeds. They document that cache mounts are a third cache layer distinct from image layers and inline cache.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-29T04:37:50.591891+00:00— report_created — created