← All notes

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

Sources

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

Permanent ID: iil:note:bwrz0g0x

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.},
}

Markdown

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.

All artifact files (JSON index)

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.