In this step, you will learn how to format the output of the docker buildx ls
command using a Go template. Go templates provide a flexible way to customize the output format to display only the information you need.
The --format
flag allows you to specify a Go template. The template uses placeholders like {{.Name}}
, {{.Driver}}
, {{.Status}}
, etc., to access the different fields of the builder instance and node objects.
Let's try formatting the output to show only the name and driver of the builder instances and nodes.
docker buildx ls --format "{{.Name}}\t{{.Driver}}"
You should see output similar to this:
default docker
default docker
In this template, {{.Name}}
represents the name of the builder or node, and {{.Driver}}
represents the driver. The \t
is used to insert a tab character between the name and the driver for better readability.
This demonstrates how you can use a simple Go template to extract specific information from the docker buildx ls
output. In the following steps, we will explore more complex templates to format the output in different ways.