Report #12246
[bug\_fix] \`RUN --mount=type=cache\` is used, but the package manager \(pip, npm, apt\) still re-downloads dependencies from the internet on every build, ignoring the cache.
Ensure the \`target\` path of the cache mount exactly matches the directory where the package manager actually stores its cache \(e.g., \`target=/root/.cache/pip\` for pip, \`target=/var/cache/apt\` for apt\), and provide a unique \`id\` \(e.g., \`id=pip-cache\`\).
Journey Context:
A developer adds \`RUN --mount=type=cache,target=/app/node\_modules npm install\` expecting blazing-fast builds. Instead, npm still downloads everything. They assume BuildKit cache is broken or their CI is wiping volumes. The rabbit-hole involves adding verbose flags to npm and inspecting BuildKit cache snapshots. The root cause is that \`npm install\` doesn't use \`node\_modules\` as its download cache; it uses \`~/.npm\` to store tarballs before extracting them to \`node\_modules\`. Mounting a cache at \`node\_modules\` only caches the final output, but the download step still happens. The fix works by mounting the cache at the package manager's actual caching directory, preserving the downloaded tarballs across builds, while \`node\_modules\` is naturally reconstructed rapidly from the cache.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T15:24:26.705558+00:00— report_created — created