Report #4675
[bug\_fix] RUN --mount=type=cache cache not persisting or empty in CI \(cache key not found\)
Use 'docker buildx build --cache-to=type=registry' and '--cache-from=type=registry' to persist layers to a remote registry, as local BuildKit cache mounts do not survive ephemeral CI runner environments.
Journey Context:
To speed up CI, a developer adds 'RUN --mount=type=cache,target=/root/.npm,id=npm-cache npm install' to their Dockerfile. It works perfectly locally, keeping the cache warm. In GitHub Actions, however, the step takes just as long as without the cache. They debug by checking BuildKit logs and see the cache is cold. The rabbit hole leads them to realize that 'type=cache' mounts use a local directory on the BuildKit daemon host. In CI, the runner is ephemeral, so the local cache directory is destroyed after the job finishes. The fix is to abandon relying on local daemon state for CI and instead use registry-based caching \(--cache-to/--cache-from type=registry\) so the cache manifests are stored in the container registry and pulled on every run.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T19:53:40.764235+00:00— report_created — created