@@ -15,16 +15,16 @@ environment variables.
1515
1616Use the ` variable ` block to define a variable.
1717
18- ``` hcl
18+ ``` hcl {title=docker-bake.hcl}
1919variable "TAG" {
2020 default = "docker.io/username/webapp:latest"
2121}
2222```
2323
2424The 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
3838defines a ` TAG ` variable with a value of ` latest ` .
3939
40- ``` hcl
40+ ``` hcl {title=docker-bake.hcl}
4141variable "TAG" {
4242 default = "latest"
4343}
@@ -46,8 +46,16 @@ variable "TAG" {
4646To 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
8795In the following example, validation is used to enforce a numeric constraint on
8896a 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
92100variable "PORT" {
93101 default = 3000 # Default value assigned to `PORT`
@@ -115,7 +123,7 @@ the variable. All conditions must be `true`.
115123
116124Here’s an example:
117125
118- ``` hcl
126+ ``` hcl {title=docker-bake.hcl}
119127# Define a variable `VAR` with multiple validation rules
120128variable "VAR" {
121129 # First validation block: Ensure the variable is not empty
@@ -148,7 +156,7 @@ dependent variables are set correctly before proceeding.
148156
149157Here’s an example:
150158
151- ``` hcl
159+ ``` hcl {title=docker-bake.hcl}
152160# Define a variable `FOO`
153161variable "FOO" {}
154162
@@ -171,8 +179,8 @@ will trigger the validation error.
171179If you want to bypass variable interpolation when parsing the Bake definition,
172180use 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,9 @@ $ docker buildx bake -f vars.hcl -f docker-bake.hcl --print app
233241``` json
234242{
235243 "target" : {
236- "default" : {
244+ printf("Hello, %s!\n\n", name_0);
245+ printf("Hello, %s!\n\n", name_0);
246+ "webapp" : {
237247 "context" : " ." ,
238248 "contexts" : {
239249 "base" : " docker.io/library/alpine:latest"
0 commit comments