Print the resulting configuration without building
In this final step, we will explore how to view the final configuration that docker buildx bake
will use for a specific target, including any overrides applied with the --set
flag, without actually triggering a build. This is useful for debugging your bake files and understanding the effective configuration before building.
The --print
flag with docker buildx bake
allows you to output the resolved configuration in JSON format.
Make sure you are in the ~/project
directory.
cd ~/project
Let's print the configuration for the my-app-dev
target.
docker buildx bake my-app-dev --print
This command will output a JSON representation of the my-app-dev
target's configuration as derived from the docker-bake.hcl
file.
{
"target": {
"my-app-dev": {
"dockerfile": "Dockerfile",
"context": ".",
"tags": ["my-app:dev"]
}
}
}
Now, let's see how the --set
flag affects the printed configuration. We will print the configuration for my-app-dev
while overriding the tag to my-app:testing
.
docker buildx bake my-app-dev --set my-app-dev.tags=my-app:testing --print
Observe the output. The tags
attribute in the JSON output should now reflect the overridden value.
{
"target": {
"my-app-dev": {
"dockerfile": "Dockerfile",
"context": ".",
"tags": ["my-app:testing"]
}
}
}
Similarly, you can print the configuration for the my-app-prod
target and override its build argument.
docker buildx bake my-app-prod --set my-app-prod.args.BUILD_ENV=staging --print
The JSON output for the my-app-prod
target will show the args
with the overridden BUILD_ENV
value.
{
"target": {
"my-app-prod": {
"dockerfile": "Dockerfile",
"context": ".",
"tags": ["my-app:prod"],
"args": {
"BUILD_ENV": "staging"
}
}
}
}
The --print
flag is a valuable tool for verifying your bake file configurations and understanding how overrides are applied before initiating potentially time-consuming builds.