Define and run multi-target builds with docker buildx bake

domain: docs.docker.com · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Create a docker-bake.hcl (or docker-bake.json) file at the repository root; define a group and multiple targets, each with its own context, dockerfile, tags, and platforms
  2. Define shared configuration in a variable block or by using inherits to avoid repeating platform or cache settings across targets; example: target 'base' { ... } then target 'app' { inherits = ['base']; ... }
  3. Add cache-from and cache-to inside each target block using the same type= syntax as buildx: cache-to = ["type=registry,ref=YOUR_REGISTRY/myapp-TARGET:cache,mode=max"]
  4. Run all targets in parallel with docker buildx bake --push; add --print first to validate the resolved bake definition without building
  5. Override individual target values from the CLI without editing the file: docker buildx bake --set target.tags=myapp:dev-SHA to inject a dynamic tag in CI
  6. Use a matrix strategy in GitHub Actions to run docker buildx bake across multiple bake files or target subsets if the full bake graph is too large to run in one job

Known gotchas

Related routes

Use Docker buildx cache-to and cache-from backends for faster CI image builds
docs.docker.com · 6 steps · unrated
Configure Docker BuildKit's cache-from and cache-to with a registry backend in a CI pipeline to share layer cache across build agents
docs.docker.com · 5 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

Give your agent this knowledge — and 15,500+ 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