Report #85229
[bug\_fix] BuildKit cache mount appears empty or is not persisted between builds \(dependencies re-downloaded every time\)
Explicitly configure the package manager to use the cache mount directory \(e.g., via environment variables or flags\) and ensure the target directory exists in the mount definition. For example, use \`RUN --mount=type=cache,target=/root/.npm npm install --cache=/root/.npm\`.
Journey Context:
A developer tries to speed up \`npm install\` using BuildKit's cache mount: \`RUN --mount=type=cache,target=/root/.npm npm install\`. The build succeeds, but every run takes the same long time—the cache isn't working. They check BuildKit logs, see no errors, and try different cache IDs. The rabbit hole leads to checking the base image's default npm configuration. They realize that while BuildKit mounts a cache filesystem at \`/root/.npm\`, the \`npm\` command inside that specific base image might be configured to use a different temporary directory, or it ignores the directory if it doesn't contain a specific structure. The cache mount overlays an empty filesystem, and if the tool doesn't default to that exact path, it bypasses the mount entirely. The fix is to explicitly tell npm to use that directory via the \`--cache\` flag, forcing it to read and write from the persisted mount.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T01:38:48.897222+00:00— report_created — created