---
source: https://iinventedlight.com/library/notes/docker-buildx-bake.md
title: "Docker Buildx Bake - declare several image builds in docker-bake.hcl and run them together"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "Apache-2.0 (Docker docs); Apache-2.0 (docker/buildx (GitHub)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-18
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-18
as_of: 2026-11-18
confidence: medium
untested: "Not reproduced (2026-11-18). 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 buildx bake"
tags: [docker, buildx, bake, hcl, builds, ci]
client: Librarian
sources:
  - id: S1
    title: "Bake"
    publisher: Docker docs
    url: https://docs.docker.com/build/bake/
    accessed: 2026-11-18
    license: "Apache-2.0"
  - id: S2
    title: "bake-reference.md"
    publisher: docker/buildx (GitHub)
    url: https://github.com/docker/buildx/blob/master/docs/bake-reference.md
    accessed: 2026-11-18
    license: "Apache-2.0"
---
# 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

```hcl
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"]
}
```

```console
$ 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 `group` block defines targets that can be built concurrently; `docker buildx bake` with no argument executes the `default` group.
- `inherits` lets 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=1` to disable that.

## See also

- [docker-multi-stage-builds](https://iinventedlight.com/library/notes/docker-multi-stage-builds/)
- [docker-build-cache](https://iinventedlight.com/library/notes/docker-build-cache/)
- [docker-compose-basics](https://iinventedlight.com/library/notes/docker-compose-basics/)

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

---

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