Docker Bake matrices: fork one target into named variants
Answer: A Bake matrix forks one target into multiple named variants from parameters that you list.
How a matrix expands
The feature works in a similar way to matrix strategies for GitHub Actions, and it cuts duplication in a Bake definition.
The matrix attribute maps parameter names to lists of values.
Bake then emits a separate target for every combination of those values.
Each generated target must have a unique name, which you control with the name attribute.
In a simple case, a target named app with tgt set to foo and bar resolves to app-foo and app-bar, and the matrix value can also set the Dockerfile build stage.
Variants, multiple axes, and maps
You can put a matrix value into build arguments and tags to produce distinct image variants, such as release and debug images tagged with the mode.
For file exports, give each variant its own output directory so one variant does not overwrite another.
Multiple keys in the matrix fork a target on more than one axis, and Bake then builds every combination, for example four targets from two stages and two versions.
The example uses replace(version, ".", "-") in the name when version values include 1.0.
If you need more than a single value per variant, use maps as matrix values.
Bake creates a target for each map, and nested fields are read with dot notation, such as item.tgt and item.version.
See also
Claims
- id: C1 claim: A matrix forks one Bake target into multiple variants. source: S1 evidence: "A matrix strategy lets you fork a single target into"
- id: C2 claim: matrix maps parameter names to lists of values. source: S2 evidence: "The matrix attribute is a map of parameter names to lists"
- id: C3 claim: Several matrix keys build every combination across those axes. source: S2 evidence: "You can specify multiple keys in your matrix to fork"
Sources
- [S1] Bake matrix targets. Docker, Inc.. https://docs.docker.com/build/bake/matrices/ . License: Apache License 2.0. Accessed 2026-11-27.
- [S2] Bake matrix targets (source). Docker, Inc.. https://raw.githubusercontent.com/docker/docs/main/content/manuals/build/bake/matrices.md . License: Apache License 2.0. Accessed 2026-11-27.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Docker, Inc., Bake matrix targets; Docker, Inc., Bake matrix targets (source). Apache-2.0 (https://raw.githubusercontent.com/docker/docs/main/LICENSE). Copyright Docker, Inc. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Docker, Inc., Bake matrix targets; Docker, Inc., Bake matrix targets (source). Apache-2.0 (https://raw.githubusercontent.com/docker/docs/main/LICENSE). Copyright Docker, Inc.
Cite this
iinventedlight. 2026. "Docker Bake matrices: fork one target into named variants." iinventedlight Library, iil:note:bwrz0g0x, version of 2026-11-27. https://iinventedlight.com/library/notes/docker-build-bake-matrices/. License: CC-BY-4.0.
@misc{iil_note_bwrz0g0x,
author = {{iinventedlight}},
title = {{Docker Bake matrices: fork one target into named variants}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-27},
url = {https://iinventedlight.com/library/notes/docker-build-bake-matrices/},
note = {Permanent ID iil:note:bwrz0g0x. 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).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- docker-build-bake-matrices.schema.json (schema; CC-BY-4.0)
- docker-build-bake-matrices.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/docker-build-bake-matrices.md.