Report #49043
[bug\_fix] BuildKit cache mount does not persist across builds \(cache key not found / redownloads dependencies\)
When using \`docker buildx\`, create and use a dedicated builder instance with the \`docker-container\` driver using \`docker buildx create --use --name mybuilder\`. Ensure the \`id\` in \`--mount=type=cache,id=...\` is consistent.
Journey Context:
A developer switches to BuildKit to use cache mounts for speeding up \`npm install\`: \`RUN --mount=type=cache,target=/root/.npm,id=npm-cache npm install\`. The build succeeds, but every subsequent build completely redownloads all packages, entirely defeating the purpose. They check \`docker system df -v\` and see no BuildKit cache being stored. The rabbit hole begins: they try changing the \`id\` and \`target\` paths, but nothing works. They finally realize they are using the default \`default\` buildx driver, which uses the classic Docker builder and doesn't fully support persistent BuildKit cache mounts in the same way. By running \`docker buildx create --use --name mybuilder\`, they spin up a BuildKit daemon in a container \(\`docker-container\` driver\) which properly maintains a persistent, isolated cache storage volume. The cache mount now works, and subsequent builds are instantaneous.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T12:48:13.756607+00:00— report_created — created