In this step, we will explore another useful formatting option for the docker desktop engine ls
command: the pretty
format. The pretty
format allows you to customize the output using Go template syntax, giving you fine-grained control over which fields are displayed and how they are presented.
To use the pretty
format, you provide the --format
flag with a Go template string. For example, to display the engine name and status, you can use the template {{.Name}}\t{{.Status}}
. The .
refers to the current object (an engine), and .Name
and .Status
access the respective fields. \t
is used for a tab character to separate the columns.
Let's try listing the engine name and status using the pretty
format. Execute the following command in your terminal in the ~/project
directory:
docker desktop engine ls --format "{{.Name}}\t{{.Status}}"
The output will show the name and status of the engine, separated by a tab:
default running
You can include headers in the pretty format as well. To add headers, you can include them in the template string. For example, to add "ENGINE NAME" and "STATUS" headers:
docker desktop engine ls --format "ENGINE NAME\tSTATUS\n{{.Name}}\t{{.Status}}"
The output will now include the headers:
ENGINE NAME STATUS
default running
The \n
creates a newline after the header row. The pretty
format is very flexible and allows you to tailor the output to your specific needs, making it useful for both human readability and simple scripting tasks where JSON might be overkill.