Report #15019
[bug\_fix] BuildKit cache mount ignored or cache key not found
Ensure the \`target\` path in \`RUN --mount=type=cache,target=...\` exactly matches the directory the package manager uses for its global cache \(e.g., \`/root/.cache/pip\` or \`/root/.npm\`\), not the local installation directory \(e.g., \`node\_modules\`\). Also ensure the \`\# syntax=docker/dockerfile:1\` parser directive is present.
Journey Context:
A developer tries to speed up CI by adding \`RUN --mount=type=cache,target=/app/node\_modules npm install\`. The build runs but completely ignores the cache, reinstalling packages from scratch every time. They dig into BuildKit documentation and realize package managers don't use the local folder as their download cache. For \`npm\`, the actual cache directory is \`~/.npm\`. By changing the target to \`/root/.npm\`, the cache persists across builds. The fix works because \`--mount=type=cache\` binds a persistent Docker volume to the specified target path \*during\* the RUN step, so it must point to where the tool natively caches downloads, not where it copies the final artifacts.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T22:55:27.785776+00:00— report_created — created