Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions content/manuals/build/bake/overrides.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ To override these attributes, you can use the following methods:

- [File overrides](#file-overrides)
- [CLI overrides](#command-line)
- [Variable overrides](#variables)
- [Environment variable overrides](#environment-variables)

## File overrides
Expand Down Expand Up @@ -247,6 +248,21 @@ Complete list of attributes that can be overridden with `--set` are:
- `tags`
- `target`

## Variables

Use `--var NAME=value` to override a declared Bake variable for a single
invocation. For example, set `TAG` without exporting it in your shell:

```console
$ docker buildx bake --var TAG=dev webapp
```

The value takes precedence over an environment variable with the same name.
Unlike `--set webapp.tags=...`, this changes the variable wherever the Bake
definition uses it. See
[Override variable values](./variables.md#override-variable-values) for
precedence, types, and repeated flags.

## Environment variables

You can also use environment variables to override configurations.
Expand Down
23 changes: 21 additions & 2 deletions content/manuals/build/bake/variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
title: Variables in Bake
linkTitle: Variables
weight: 40
description:
description: Define, override, and validate variables in Docker Bake files
keywords: build, buildx, bake, buildkit, hcl, variables
---

You can define and use variables in a Bake file to set attribute values,
interpolate them into other values, and perform arithmetic operations.
Variables can be defined with default values, and can be overridden with
environment variables.
the `--var` flag or environment variables.

## Using variables as attribute values

Expand All @@ -31,6 +31,25 @@ target "webapp" {
}
```

## Override variable values

Use `--var NAME=value` to override a declared variable for one Bake invocation
without changing your shell's environment:

```console
$ docker buildx bake --var TAG=docker.io/username/webapp:dev webapp
```

Repeat the flag to set multiple variables. If you repeat a name, the last
value wins. Explicit `--var` values take precedence over environment variables
with the same name and over defaults in the Bake file. Values are converted
to the declared variable type.

This flag also works when environment-based variable lookups are disabled
with `BUILDX_BAKE_DISABLE_VARS_ENV_LOOKUP=1`. Use `--var` to set a variable
used in expressions throughout the definition; use `--set` to override a
specific target attribute. See [Overriding configurations](./overrides.md).

## Interpolate variables into values

Bake supports string interpolation of variables into values. You can use the
Expand Down
Loading