Report #102944
[bug\_fix] Build reuses stale package indexes or old compiled artifacts even with --no-cache when using RUN --mount=type=cache
Cache mounts persist outside the layer cache and are not cleared by \`--no-cache\`. To force a clean state, prune the BuildKit cache with \`docker buildx prune\` or \`docker builder prune\`. For reproducibility, do not store files required for correctness in cache mounts; use them only for performance \(for example, package-manager caches\). You can also use a different \`id=\` to isolate caches.
Journey Context:
I used \`RUN --mount=type=cache,target=/root/.cache npm install\` to speed up builds. After a broken release, I ran \`docker build --no-cache\` but the build still used an old \`node\_modules\` state stored in the cache mount. I tried \`docker system prune\`, which did not help. Reading the BuildKit docs clarified that \`--no-cache\` only skips the layer cache; cache mounts are persistent volumes managed by BuildKit. Pruning the builder cache fixed it.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-10T04:44:48.574810+00:00— report_created — created