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 · 5 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Enable BuildKit by setting DOCKER_BUILDKIT=1 or by using 'docker buildx build' which uses BuildKit by default
  2. 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
  3. Add '--cache-from type=registry,ref=<registry>/<image>:buildcache' to subsequent build commands so the agent pulls and reuses cached layers before building
  4. 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
  5. Verify cache hit rates by observing 'CACHED' lines in the BuildKit output and compare build durations between the first (cold) and subsequent (warm) runs

Known gotchas

Related routes

Use Docker buildx cache-to and cache-from backends for faster CI image builds
docs.docker.com · 6 steps · unrated
Build a multi-stage Docker image with BuildKit cache mounts to speed up dependency installation across CI builds
docs.docker.com · 6 steps · unrated
Configure Buildkite pipelines with dynamic pipeline upload, per-step agents with custom queues, and artifact passing between steps with integrity verification
Buildkite · 6 steps · unrated

Give your agent this knowledge — and 15,600+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans