Docker Buildx Bake - declare several image builds in docker-bake.hcl and run them together
Answer: Write a docker-bake.hcl with target blocks (context, dockerfile, args, tags) and a group "default" listing them, then run docker buildx bake. Bake defines your build configuration using a declarative file and runs multiple builds concurrently with a single invocation.
Example
variable "TAG" {
default = "latest"
}
group "default" {
targets = ["frontend", "backend"]
}
target "frontend" {
context = "./frontend"
dockerfile = "frontend.Dockerfile"
args = { NODE_VERSION = "22" }
tags = ["myapp/frontend:${TAG}"]
}
target "backend" {
context = "./backend"
dockerfile = "backend.Dockerfile"
tags = ["myapp/backend:${TAG}"]
}
target "backend-release" {
inherits = ["backend"]
platforms = ["linux/amd64", "linux/arm64"]
}
$ docker buildx bake
$ TAG=v2 docker buildx bake backend-release
$ docker buildx bake --file ../docker/bake.hcl --print
How files are found
- A Bake file can be written in HCL, JSON, or a Compose YAML file.
- Without
--file, Bake looks in the current working directory in this order:compose.yaml,compose.yml,docker-compose.yml,docker-compose.yaml,docker-bake.json,docker-bake.hcl,docker-bake.override.json,docker-bake.override.hcl. - When several Bake files exist, they are combined into one definition following the lookup order; duplicate attributes are merged or overridden by the last occurrence, depending on the attribute.
Targets and groups
- A
groupblock defines targets that can be built concurrently;docker buildx bakewith no argument executes thedefaultgroup. inheritslets a target reuse attributes from other targets.
Variables
- A variable can feed a Dockerfile build argument, or be interpolated in attribute values as
${NAME}. - An environment variable with the same name as a declared Bake variable overrides its default. Set
BUILDX_BAKE_DISABLE_VARS_ENV_LOOKUP=1to disable that.
See also
Claims
- id: C1 claim: Bake runs multiple builds concurrently with one invocation. source: S1 evidence: "It also lets you run multiple builds concurrently with a single invocation."
- id: C2 claim: A Bake file can be HCL or JSON. source: S1 evidence: "A Bake file can be written in HCL or JSON format."
- id: C3 claim: Multiple Bake files are merged into one definition. source: S2 evidence: "all files are merged into a single definition."
Sources
- [S1] Bake. Docker docs. https://docs.docker.com/build/bake/ . License: Apache-2.0. Accessed 2026-11-18.
- [S2] bake-reference.md. docker/buildx (GitHub). https://github.com/docker/buildx/blob/master/docs/bake-reference.md . License: Apache-2.0. Accessed 2026-11-18.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Docker docs, Bake; docker/buildx (GitHub), bake-reference.md. Apache-2.0 (https://raw.githubusercontent.com/docker/docs/main/LICENSE). Copyright Docker, Inc. Apache-2.0 (https://raw.githubusercontent.com/docker/buildx/master/LICENSE). Copyright Docker, Inc. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Docker docs, Bake; docker/buildx (GitHub), bake-reference.md. Apache-2.0 (https://raw.githubusercontent.com/docker/docs/main/LICENSE). Copyright Docker, Inc. Apache-2.0 (https://raw.githubusercontent.com/docker/buildx/master/LICENSE). Copyright Docker, Inc.
Cite this
iinventedlight. 2026. "Docker Buildx Bake - declare several image builds in docker-bake.hcl and run them together." iinventedlight Library, iil:note:qeheczck, version of 2026-11-18. https://iinventedlight.com/library/notes/docker-buildx-bake/. License: CC-BY-4.0.
@misc{iil_note_qeheczck,
author = {{iinventedlight}},
title = {{Docker Buildx Bake - declare several image builds in docker-bake.hcl and run them together}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-18},
url = {https://iinventedlight.com/library/notes/docker-buildx-bake/},
note = {Permanent ID iil:note:qeheczck. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/docker-buildx-bake.md.