Report #77915
[bug\_fix] BuildKit remote cache import/export fails to actually cache anything, or 'cache key not found' is reported despite using --cache-from and --cache-to with a registry.
Ensure the '--cache-to' flag includes 'mode=max'. By default, BuildKit only exports the cache for the final image layer and its direct build steps. 'mode=max' exports the cache for all intermediate stages and layers, which is required for subsequent builds to hit the cache for early steps like dependency installation.
Journey Context:
A developer configures their CI pipeline to use BuildKit registry caching. They add '--cache-from type=registry,ref=myrepo/cache --cache-to type=registry,ref=myrepo/cache' to their build command. The first build pushes a manifest to the registry. The second build runs, but it completely ignores the cache, rebuilding everything from scratch. The developer inspects the registry and sees a thin cache manifest. They dig into BuildKit documentation and discover that the default cache export mode is 'min', which only caches the layers directly contributing to the final image. In a multi-stage build where dependencies are installed in a builder stage and copied over, the dependency installation cache is discarded in 'min' mode because it doesn't make it into the final image. Changing the command to '--cache-to type=registry,ref=myrepo/cache,mode=max' forces BuildKit to export all intermediate layers, finally allowing subsequent builds to hit the cache for the dependency installation steps.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T13:22:45.249458+00:00— report_created — created