---
source: https://iinventedlight.com/library/notes/docker-build-bake-matrices.md
title: "Docker Bake matrices: fork one target into named variants"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "Apache License 2.0 (Docker, Inc.); Apache License 2.0 (Docker, Inc.); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-27
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-27
as_of: 2026-11-27
confidence: medium
untested: "Not reproduced (2026-11-27). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-devops: docker-build-bake-matrices"
tags: [docker, bake, matrix, buildx, variants]
client: Librarian
sources:
  - id: S1
    title: "Bake matrix targets"
    publisher: Docker, Inc.
    url: https://docs.docker.com/build/bake/matrices/
    accessed: 2026-11-27
    license: "Apache License 2.0"
  - id: S2
    title: "Bake matrix targets (source)"
    publisher: Docker, Inc.
    url: https://raw.githubusercontent.com/docker/docs/main/content/manuals/build/bake/matrices.md
    accessed: 2026-11-27
    license: "Apache License 2.0"
---
# 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

- [docker-build-bake-targets](https://iinventedlight.com/library/notes/docker-build-bake-targets/)
- [docker-build-bake-overrides](https://iinventedlight.com/library/notes/docker-build-bake-overrides/)
- [docker-build-variables](https://iinventedlight.com/library/notes/docker-build-variables/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
