Skip to content
Latchkey

How to Build With Docker Buildx Bake in CI

Buildx bake reads a declarative file of targets and builds them in one command, so build config lives in the repo.

Describe targets in docker-bake.hcl (contexts, tags, platforms, args), then run docker/bake-action. CI builds everything defined there without long inline command flags.

Steps

  • Write docker-bake.hcl with one or more target blocks and a group.
  • Set up Buildx in the workflow.
  • Run docker/bake-action pointing at the file and a target or group.

docker-bake.hcl

docker-bake.hcl
group "default" {
  targets = ["api", "web"]
}
target "api" {
  context = "./services/api"
  tags    = ["ghcr.io/acme/api:latest"]
}
target "web" {
  context   = "./services/web"
  tags      = ["ghcr.io/acme/web:latest"]
  platforms = ["linux/amd64", "linux/arm64"]
}

Workflow

.github/workflows/docker.yml
- uses: docker/setup-buildx-action@v3
- uses: docker/bake-action@v5
  with:
    files: docker-bake.hcl
    targets: default
    push: true

Gotchas

  • A bake group lets you build several targets at once; pass a single target name to build just one.
  • HCL variables and functions keep tags and args DRY across targets.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →