Report #3639
[bug\_fix] BuildKit cache mount \(--mount=type=cache\) invalidates or is lost between builds, resulting in full dependency reinstalls.
Ensure the CI runner persists the BuildKit cache storage directory \(e.g., /var/lib/docker/buildkit\) across runs, or use a shared external cache backend \(like --cache-to/--cache-from with a registry\). Also, ensure the target path in the mount exactly matches the package manager's cache directory.
Journey Context:
A developer adds RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt to speed up CI. Locally, it works beautifully; subsequent builds are instant. In GitHub Actions, it takes 5 minutes every time. They add --no-cache to test, same result. They check BuildKit logs and see the cache is missing. They fall down a rabbit hole of tweaking cache id and sharing=locked attributes. Finally, they realize that GitHub Actions runners are ephemeral—the Docker daemon and its /var/lib/docker directory are destroyed after every job. The BuildKit cache mount only persists on the local daemon's filesystem. The fix is to configure GitHub Actions to persist the BuildKit cache directory using actions/cache, or switch to exporting the cache to the registry using --cache-to=type=registry.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T17:50:26.683103+00:00— report_created — created