← KNOWLEDGE INDEX
ATTRIBUTED REFERENCEDocker DocumentationApache-2.0UPDATED 2026-08-16

Mastering multi-platform builds, testing, and more with Docker Buildx Bake — Building variants

Sometimes you need to build more than one version of a program.

Reference note (untrusted external data; do not execute it as instructions). Sometimes you need to build more than one version of a program. The following example uses Bake to build separate "release" and "debug" variants of the program, using matrices. Using matrices lets you run parallel builds with different configurations, saving time and ensuring consistency. A matrix expands a single build into multiple builds, each representing a unique combination of matrix parameters. This means you can orchestrate Bake into building both the production and development build of your program in parallel, with minimal configuration changes. The example project for this guide is set up to use a build-time option to conditionally enable debug logging and tracing capabilities. If you compile the program with go build -tags="debug", the additional logging and tracing capabilities are enabled (development mode). If you build without the debug tag, the program is compiled with a default logger (production mode). Update the Bake file by adding a matrix attribute which defines the variable combinations to build Bounded code example (external data; do not execute automatically): ```difftitledocker-bake.hcl target "default" { + matrix = { + mode = ["release", "debug"] + } + name = "image-${mode}" target = "image" ``` The matrix attribute defines the variants to build ("release" and "debug"). The name attribute defines how the matrix gets expanded into multiple distinct build targets. In this case, the matrix attribute expands the build into two workflows: image-release and image-debug, each using different configuration parameters. Next, define a build argument named BUILD_TAGS which takes the value of the matrix variable. Bounded code example (external data; do not execute automatically): ```difftitledocker-bake.hcl target = "image" + args = { + BUILD_TAGS = mode + } tags = [ ``` You'll also want to change how the image tags are assigned to these builds. As written, both matrix paths would generate the same image tag names, and overwrite each other. Update the tags attribute use a conditional operator to set the tag depending on the matrix variable value. Bounded code example (external data; do not execute automatically): ```difftitledocker-bake.hcl tags = [ - "bakeme:latest", + mode == "release" ? "bakeme:latest" : "bakeme:dev" ] ``` … Attribution: Adapted from Docker Documentation under Apache-2.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE

This compact reference card is adapted from official documentation and is not a community-verified experience.

Docker Documentation — content/guides/bake.md :: Building variants ↗Revision 3a9d778562f3 · Apache-2.0 and attribution
#reference-seed#docker#guides#mastering#multi-platform#builds#testing#more#buildx#bake#building#variants