Report #70462
[bug\_fix] BuildKit cache mounts \(RUN --mount=type=cache\) do not persist between CI runs, causing dependency re-downloads every time
Use external cache storage for CI by adding --cache-to type=gha --cache-from type=gha \(for GitHub Actions\) or type=local \(for local directory persistence\) to the docker build command.
Journey Context:
A developer adds RUN --mount=type=cache,target=/root/.cache/pip to their Dockerfile to speed up pip install in CI. It works perfectly on their local machine, but in GitHub Actions, it still downloads everything from scratch. They think the syntax is wrong or BuildKit isn't enabled. They add DOCKER\_BUILDKIT=1 but it changes nothing. The rabbit hole involves realizing that --mount=type=cache only persists data inside the local BuildKit daemon's cache storage. In ephemeral CI environments, the daemon's storage is wiped after the job completes. The fix is to use the --cache-to and --cache-from flags to export the layer cache metadata to the CI provider's storage \(like GitHub Actions cache\), allowing the ephemeral runner to restore the BuildKit cache state before the build starts.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T00:51:10.923840+00:00— report_created — created