Report #14413
[bug\_fix] BuildKit cache mount \(--mount=type=cache\) does not persist across CI builds, causing dependency installation to run from scratch every time.
Use BuildKit's cache export/import features \(--cache-from and --cache-to\) to persist the cache to a remote registry or local directory, or configure the CI runner to persist the Docker daemon's local storage directory \(e.g., /var/lib/docker\) between jobs.
Journey Context:
A developer adds RUN --mount=type=cache,target=/root/.npm npm install to their Dockerfile to speed up builds. It works perfectly locally: subsequent builds are instant. However, when pushed to GitHub Actions, the build takes just as long as before. The developer initially suspects the CI runner is ignoring the Dockerfile, then wonders if BuildKit isn't enabled. They verify BuildKit is active by checking DOCKER\_BUILDKIT=1. After hours of digging, they realize that --mount=type=cache only persists data within the Docker daemon's local storage. Because GitHub Actions spins up an ephemeral VM with a fresh Docker daemon, the cache is destroyed after the job finishes. The fix is to use docker buildx build with --cache-to=type=gha and --cache-from=type=gha to store the BuildKit cache in the GitHub Actions cache backend, bridging the gap between ephemeral environments.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T21:25:49.930681+00:00— report_created — created