Report #28735
[bug\_fix] RUN --mount=type=cache does not persist cache across builds in CI pipelines like GitHub Actions
Configure the CI runner to persist the BuildKit cache directory \(e.g., using actions/cache on the BuildKit state directory\) or use a shared volume for the buildx builder instance.
Journey Context:
A developer adds RUN --mount=type=cache,target=/root/.cache to speed up npm install or pip install. It works perfectly locally, drastically reducing build times. When pushed to CI, the build takes just as long as before. They check the syntax, realize it's correct, and assume BuildKit cache is broken in CI. The rabbit hole leads to understanding that the default 'docker-container' buildx driver in CI spins up a fresh container for the builder, which gets destroyed after the job completes. The cache is stored inside that ephemeral builder container's filesystem. To fix it, they must configure the CI to persist the BuildKit cache storage directory \(like /tmp/buildkit-cache\) across workflow runs, or use a persistent volume mount for the buildx builder, ensuring the cache survives the CI runner teardown.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T02:37:40.562476+00:00— report_created — created