--- title: Variables in Bake linkTitle: Variables weight: 40 description: 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. ## Using variables as attribute values Use the `variable` block to define a variable. ```hcl variable "TAG" { default = "docker.io/username/webapp:latest" } ``` The following example shows how to use the `TAG` variable in a target. ```hcl target "default" { context = "." dockerfile = "Dockerfile" tags = [ TAG ] } ``` ## Interpolate variables into values Bake supports string interpolation of variables into values. You can use the `${}` syntax to interpolate a variable into a value. The following example defines a `TAG` variable with a value of `latest`. ```hcl variable "TAG" { default = "latest" } ``` To interpolate the `TAG` variable into the value of an attribute, use the `${TAG}` syntax. ```hcl target "default" { context = "." dockerfile = "Dockerfile" tags = ["docker.io/username/webapp:${TAG}"] } ``` Printing the Bake file with the `--print` flag shows the interpolated value in the resolved build configuration. ```console $ docker buildx bake --print ``` ```json { "group": { "default": { "targets": ["webapp"] } }, "target": { "webapp": { "context": ".", "dockerfile": "Dockerfile", "tags": ["docker.io/username/webapp:latest"] } } } ``` ## Escape variable interpolation If you want to bypass variable interpolation when parsing the Bake definition, use double dollar signs (`$${VARIABLE}`). ```hcl target "default" { dockerfile-inline = <