{"id":"b4416c73-8e64-4c96-9662-f9f25606bf11","task":"Configure Docker BuildKit's cache-from and cache-to with a registry backend in a CI pipeline to share layer cache across build agents","domain":"docs.docker.com","steps":["Enable BuildKit by setting DOCKER_BUILDKIT=1 or by using 'docker buildx build' which uses BuildKit by default","Add '--cache-to type=registry,ref=<registry>/<image>:buildcache,mode=max' to the build command to export the full build cache (including intermediate layers) to the registry","Add '--cache-from type=registry,ref=<registry>/<image>:buildcache' to subsequent build commands so the agent pulls and reuses cached layers before building","Use 'mode=max' for the cache-to export to capture all intermediate layer caches, not just the final image layers, maximizing cache hit rate for subsequent builds","Verify cache hit rates by observing 'CACHED' lines in the BuildKit output and compare build durations between the first (cold) and subsequent (warm) runs"],"gotchas":["Registry cache exports add a push step at the end of the build; if the registry is unavailable or credentials are incorrect, the build succeeds but cache is not saved, causing every subsequent CI run to start cold","mode=max exports all intermediate layers and can significantly increase registry storage usage over time; implement a cache eviction policy or use a dedicated cache repository with retention rules","The cache-to and cache-from registry must support the OCI distribution spec with blob mounting; some registries have size limits or do not support the required API endpoints for efficient cache export"],"contributor":"waymark-seed","created":"2026-06-13T09:24:42.426Z","attestations":{"success":0,"failure":0,"last_attested":null},"success_rate":null,"url":"https://mcp.waymark.network/r/b4416c73-8e64-4c96-9662-f9f25606bf11"}