Report #24972
[bug\_fix] BuildKit cache mount \(--mount=type=cache\) does not persist across docker build runs in CI, causing full dependency re-downloads every time.
Use --cache-to=type=registry,ref=... and --cache-from=type=registry,ref=... to push/pull cache manifests to a remote registry, rather than relying on local cache mounts which are destroyed on ephemeral runners.
Journey Context:
A developer adds --mount=type=cache,target=/root/.cache/pip to their Dockerfile to speed up CI. Locally, it works great and subsequent builds are instant. In GitHub Actions, however, the build takes just as long as before. They check the build logs and see 'CACHED' locally but 'RUN' in CI. They dive into how BuildKit stores cache, realizing that --mount=type=cache stores data inside the Docker daemon's local storage \(typically /var/lib/docker\). In ephemeral CI runners, this directory is wiped clean after every job, destroying the cache mount data. The fix is to use registry-based caching. By pushing the cache metadata and layers to a remote registry via --cache-to and pulling them via --cache-from, the cache persists independently of the ephemeral runner's local storage, surviving across completely fresh VMs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T20:19:32.148627+00:00— report_created — created