Skip to content

Commit 2c8d8f2

Browse files
fix: invalid command, unrelated output chunks, too large minimal exam… (#21859)
FIXes in the Docker Bake documentation. ## Description [x] Commands not matching outputs: _(e.g.: the presence of a group on the CLI affect the group section in the output)_ [x] Some file not being named bring about confusion to the reader _(e.g.: [Using a Target as Build Context](https://docs.docker.com/build/bake/contexts/#using-a-target-as-a-build-context) is not clear about needed two distinct Dockerfiles, or [Using a secondary source directory](https://docs.docker.com/build/bake/contexts/#using-a-secondary-source-directory) about the fact that the first stage in the Dockerfile does not have to be defined at all)_ [x] Multiple confusing relationships between input and output _(e.g.: the [Variables in Bake](https://docs.docker.com/build/bake/variables/) part shows multiple `webapp` target in the outputs whilst the HCL input only defines a `default` target)_ ## Related issues or tickets <!-- Related issues, pull requests, or Jira tickets --> ## Reviews <!-- Notes for reviewers here --> <!-- List applicable reviews (optionally @tag reviewers) --> - [ ] Technical review - [x] Editorial review - [ ] Product review --------- Signed-off-by: Salathiel <[email protected]> Co-authored-by: David Karlsson <[email protected]>
1 parent 0348157 commit 2c8d8f2

9 files changed

+52
-50
lines changed

content/manuals/build/bake/_index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ A Bake file can be written in HCL, JSON, or YAML formats, where the YAML format
1414
is an extension of a Docker Compose file. Here's an example Bake file in HCL
1515
format:
1616

17-
```hcl
17+
```hcl {title=docker-bake.hcl}
1818
group "default" {
1919
targets = ["frontend", "backend"]
2020
}

content/manuals/build/bake/contexts.md

+14-15
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,13 @@ Supported context values are:
2929

3030
## Pinning alpine image
3131

32-
```dockerfile
32+
```dockerfile {title=Dockerfile}
3333
# syntax=docker/dockerfile:1
3434
FROM alpine
3535
RUN echo "Hello world"
3636
```
3737

38-
```hcl
39-
# docker-bake.hcl
38+
```hcl {title=docker-bake.hcl}
4039
target "app" {
4140
contexts = {
4241
alpine = "docker-image://alpine:3.13"
@@ -46,16 +45,14 @@ target "app" {
4645

4746
## Using a secondary source directory
4847

49-
```dockerfile
50-
# syntax=docker/dockerfile:1
51-
FROM scratch AS src
52-
48+
```dockerfile {title=Dockerfile}
5349
FROM golang
5450
COPY --from=src . .
5551
```
5652

57-
```hcl
58-
# docker-bake.hcl
53+
```hcl {title=docker-bake.hcl}
54+
# Running `docker buildx bake app` will result in `src` not pointing
55+
# to some previous build stage but to the client filesystem, not part of the context.
5956
target "app" {
6057
contexts = {
6158
src = "../path/to/source"
@@ -68,14 +65,16 @@ target "app" {
6865
To use a result of one target as a build context of another, specify the target
6966
name with `target:` prefix.
7067

71-
```dockerfile
68+
```dockerfile {title=baseapp.Dockerfile}
69+
FROM scratch
70+
```
71+
```dockerfile {title=Dockerfile}
7272
# syntax=docker/dockerfile:1
7373
FROM baseapp
7474
RUN echo "Hello world"
7575
```
7676

77-
```hcl
78-
# docker-bake.hcl
77+
```hcl {title=docker-bake.hcl}
7978
target "base" {
8079
dockerfile = "baseapp.Dockerfile"
8180
}
@@ -119,7 +118,7 @@ result in significant impact on build time, depending on your build
119118
configuration. For example, say you have a Bake file that defines the following
120119
group of targets:
121120

122-
```hcl
121+
```hcl {title=docker-bake.hcl}
123122
group "default" {
124123
targets = ["target1", "target2"]
125124
}
@@ -148,7 +147,7 @@ context that only loads the context files, and have each target that needs
148147
those files reference that named context. For example, the following Bake file
149148
defines a named target `ctx`, which is used by both `target1` and `target2`:
150149

151-
```hcl
150+
```hcl {title=docker-bake.hcl}
152151
group "default" {
153152
targets = ["target1", "target2"]
154153
}
@@ -177,7 +176,7 @@ The named context `ctx` represents a Dockerfile stage, which copies the files
177176
from its context (`.`). Other stages in the Dockerfile can now reference the
178177
`ctx` named context and, for example, mount its files with `--mount=from=ctx`.
179178

180-
```dockerfile
179+
```dockerfile {title=Dockerfile}
181180
FROM scratch AS ctx
182181
COPY --link . .
183182

content/manuals/build/bake/expressions.md

+2-7
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Printing the Bake file with the `--print` flag shows the evaluated value for
3030
the `answer` build argument.
3131

3232
```console
33-
$ docker buildx bake --print app
33+
$ docker buildx bake --print
3434
```
3535

3636
```json
@@ -76,13 +76,8 @@ $ docker buildx bake --print
7676

7777
```json
7878
{
79-
"group": {
80-
"default": {
81-
"targets": ["default"]
82-
}
83-
},
8479
"target": {
85-
"webapp": {
80+
"default": {
8681
"context": ".",
8782
"dockerfile": "Dockerfile",
8883
"tags": ["my-image:latest"]

content/manuals/build/bake/inheritance.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Targets can inherit attributes from other targets, using the `inherits`
1010
attribute. For example, imagine that you have a target that builds a Docker
1111
image for a development environment:
1212

13-
```hcl
13+
```hcl {title=docker-bake.hcl}
1414
target "app-dev" {
1515
args = {
1616
GO_VERSION = "{{% param example_go_version %}}"
@@ -28,7 +28,7 @@ slightly different attributes for a production build. In this example, the
2828
`app-release` target inherits the `app-dev` target, but overrides the `tags`
2929
attribute and adds a new `platforms` attribute:
3030

31-
```hcl
31+
```hcl {title=docker-bake.hcl}
3232
target "app-release" {
3333
inherits = ["app-dev"]
3434
tags = ["docker.io/username/myapp:latest"]
@@ -43,7 +43,7 @@ shared attributes for all or many of the build targets in the project. For
4343
example, the following `_common` target defines a common set of build
4444
arguments:
4545

46-
```hcl
46+
```hcl {title=docker-bake.hcl}
4747
target "_common" {
4848
args = {
4949
GO_VERSION = "{{% param example_go_version %}}"
@@ -55,7 +55,7 @@ target "_common" {
5555
You can then inherit the `_common` target in other targets to apply the shared
5656
attributes:
5757

58-
```hcl
58+
```hcl {title=docker-bake.hcl}
5959
target "lint" {
6060
inherits = ["_common"]
6161
dockerfile = "./dockerfiles/lint.Dockerfile"
@@ -88,7 +88,7 @@ When a target inherits another target, it can override any of the inherited
8888
attributes. For example, the following target overrides the `args` attribute
8989
from the inherited target:
9090

91-
```hcl
91+
```hcl {title=docker-bake.hcl}
9292
target "app-dev" {
9393
inherits = ["_common"]
9494
args = {
@@ -110,7 +110,7 @@ The `inherits` attribute is a list, meaning you can reuse attributes from
110110
multiple other targets. In the following example, the app-release target reuses
111111
attributes from both the `app-dev` and `_common` targets.
112112

113-
```hcl
113+
```hcl {title=docker-bake.hcl}
114114
target "_common" {
115115
args = {
116116
GO_VERSION = "{{% param example_go_version %}}"

content/manuals/build/bake/introduction.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ $ docker build \
7171

7272
The Bake equivalent would be:
7373

74-
```hcl
74+
```hcl {title=docker-bake.hcl}
7575
target "myapp" {
7676
context = "."
7777
dockerfile = "Dockerfile"

content/manuals/build/bake/matrices.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ should resolve, use the name attribute.
1919
The following example resolves the app target to `app-foo` and `app-bar`. It
2020
also uses the matrix value to define the [target build stage](/build/bake/reference/#targettarget).
2121

22-
```hcl
22+
```hcl {title=docker-bake.hcl}
2323
target "app" {
2424
name = "app-${tgt}"
2525
matrix = {
@@ -73,7 +73,7 @@ The following example builds four targets:
7373
- `app-bar-1-0`
7474
- `app-bar-2-0`
7575

76-
```hcl
76+
```hcl {title=docker-bake.hcl}
7777
target "app" {
7878
name = "app-${tgt}-${replace(version, ".", "-")}"
7979
matrix = {
@@ -98,7 +98,7 @@ The following example builds two targets:
9898
- `app-foo-1-0`
9999
- `app-bar-2-0`
100100

101-
```hcl
101+
```hcl {title=docker-bake.hcl}
102102
target "app" {
103103
name = "app-${item.tgt}-${replace(item.version, ".", "-")}"
104104
matrix = {

content/manuals/build/bake/remote-definition.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ execution context as named contexts.
9191
The following example defines the `docs` context as `./src/docs/content`,
9292
relative to the current working directory where Bake is run as a named context.
9393

94-
```hcl
94+
```hcl {title=docker-bake.hcl}
9595
target "default" {
9696
contexts = {
9797
docs = "cwd://src/docs/content"

content/manuals/build/bake/targets.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ keywords: bake, target, targets, buildx, docker, buildkit, default
99
A target in a Bake file represents a build invocation. It holds all the
1010
information you would normally pass to a `docker build` command using flags.
1111

12-
```hcl
12+
```hcl {title=docker-bake.hcl}
1313
target "webapp" {
1414
dockerfile = "webapp.Dockerfile"
1515
tags = ["docker.io/username/webapp:latest"]
@@ -35,7 +35,7 @@ $ docker buildx bake webapp api tests
3535
If you don't specify a target when running `docker buildx bake`, Bake will
3636
build the target named `default`.
3737

38-
```hcl
38+
```hcl {title=docker-bake.hcl}
3939
target "default" {
4040
dockerfile = "webapp.Dockerfile"
4141
tags = ["docker.io/username/webapp:latest"]
@@ -61,7 +61,7 @@ For all the properties you can set for a target, see the [Bake reference](/build
6161
You can group targets together using the `group` block. This is useful when you
6262
want to build multiple targets at once.
6363

64-
```hcl
64+
```hcl {title=docker-bake.hcl}
6565
group "all" {
6666
targets = ["webapp", "api", "tests"]
6767
}

content/manuals/build/bake/variables.md

+21-13
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ environment variables.
1515

1616
Use the `variable` block to define a variable.
1717

18-
```hcl
18+
```hcl {title=docker-bake.hcl}
1919
variable "TAG" {
2020
default = "docker.io/username/webapp:latest"
2121
}
2222
```
2323

2424
The following example shows how to use the `TAG` variable in a target.
2525

26-
```hcl
27-
target "default" {
26+
```hcl {title=docker-bake.hcl}
27+
target "webapp" {
2828
context = "."
2929
dockerfile = "Dockerfile"
3030
tags = [ TAG ]
@@ -37,7 +37,7 @@ Bake supports string interpolation of variables into values. You can use the
3737
`${}` syntax to interpolate a variable into a value. The following example
3838
defines a `TAG` variable with a value of `latest`.
3939

40-
```hcl
40+
```hcl {title=docker-bake.hcl}
4141
variable "TAG" {
4242
default = "latest"
4343
}
@@ -46,8 +46,16 @@ variable "TAG" {
4646
To interpolate the `TAG` variable into the value of an attribute, use the
4747
`${TAG}` syntax.
4848

49-
```hcl
50-
target "default" {
49+
```hcl {title=docker-bake.hcl}
50+
group "default" {
51+
targets = [ "webapp" ]
52+
}
53+
54+
variable "TAG" {
55+
default = "latest"
56+
}
57+
58+
target "webapp" {
5159
context = "."
5260
dockerfile = "Dockerfile"
5361
tags = ["docker.io/username/webapp:${TAG}"]
@@ -87,7 +95,7 @@ range, or other condition, you can define custom validation rules using the
8795
In the following example, validation is used to enforce a numeric constraint on
8896
a variable value; the `PORT` variable must be 1024 or higher.
8997

90-
```hcl
98+
```hcl {title=docker-bake.hcl}
9199
# Define a variable `PORT` with a default value and a validation rule
92100
variable "PORT" {
93101
default = 3000 # Default value assigned to `PORT`
@@ -115,7 +123,7 @@ the variable. All conditions must be `true`.
115123

116124
Here’s an example:
117125

118-
```hcl
126+
```hcl {title=docker-bake.hcl}
119127
# Define a variable `VAR` with multiple validation rules
120128
variable "VAR" {
121129
# First validation block: Ensure the variable is not empty
@@ -148,7 +156,7 @@ dependent variables are set correctly before proceeding.
148156

149157
Here’s an example:
150158

151-
```hcl
159+
```hcl {title=docker-bake.hcl}
152160
# Define a variable `FOO`
153161
variable "FOO" {}
154162
@@ -171,8 +179,8 @@ will trigger the validation error.
171179
If you want to bypass variable interpolation when parsing the Bake definition,
172180
use double dollar signs (`$${VARIABLE}`).
173181

174-
```hcl
175-
target "default" {
182+
```hcl {title=docker-bake.hcl}
183+
target "webapp" {
176184
dockerfile-inline = <<EOF
177185
FROM alpine
178186
ARG TARGETARCH
@@ -215,7 +223,7 @@ variable "BASE_LATEST" {
215223
default = "${BASE_IMAGE}:latest"
216224
}
217225
218-
target "default" {
226+
target "webapp" {
219227
contexts = {
220228
base = BASE_LATEST
221229
}
@@ -233,7 +241,7 @@ $ docker buildx bake -f vars.hcl -f docker-bake.hcl --print app
233241
```json
234242
{
235243
"target": {
236-
"default": {
244+
"webapp": {
237245
"context": ".",
238246
"contexts": {
239247
"base": "docker.io/library/alpine:latest"

0 commit comments

Comments
 (0)