Report #2235
[bug\_fix] RUN --mount=type=cache runs completely from scratch on every CI run
Use \`--cache-to\` and \`--cache-from\` with an external storage backend \(like registry or local\) to persist the BuildKit cache across isolated CI runs.
Journey Context:
A developer adds \`RUN --mount=type=cache,target=/root/.npm npm install\` to their Dockerfile. Locally, it works beautifully—subsequent builds take seconds. However, in their GitHub Actions CI pipeline, the build is as slow as ever. They check the logs and see the cache mount is empty every time. They realize that \`--mount=type=cache\` only persists on the host's filesystem. In CI, the \`docker-container\` builder is ephemeral and destroyed after the job, taking the local cache with it. To fix this, they configure \`buildx\` to export the cache manifest and layers to their container registry using \`--cache-to=type=registry,ref=myrepo/cache\` and pull it at the start of the next build with \`--cache-from=type=registry,ref=myrepo/cache\`.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T10:19:36.753063+00:00— report_created — created