Report #104251
[bug\_fix] RUN --mount=type=cache not persisting between builds
Use a named cache mount with a unique ID \(e.g., \`--mount=type=cache,target=/root/.cache,id=my-cache\`\) and ensure the build command does not use \`--no-cache\`. For CI, configure a shared cache location via BuildKit's \`--cache-to\` and \`--cache-from\`.
Journey Context:
A developer tried to speed up \`npm install\` by using \`RUN --mount=type=cache,target=/root/.npm\`. The first build downloaded packages \(slow\), but subsequent builds re-downloaded everything. They tried different targets, setting \`NPM\_CONFIG\_CACHE\`, but no luck. The root cause: BuildKit's cache mounts are ephemeral and not persisted across builds unless explicitly saved. The developer was using \`docker build\` without any cache export. The fix: either use \`--cache-to\` to export cache to a registry, or, for local development, rely on Docker's default layer caching instead of cache mounts. The cache mount only persists within a single build session, not across separate \`docker build\` invocations.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-19T20:07:05.636073+00:00— report_created — created