Format command and log output (original) (raw)
Docker supportsGo templates which you can use to manipulate the output format of certain commands and log drivers.
Docker provides a set of basic functions to manipulate template elements. All of these examples use the docker inspect
command, but many other CLI commands have a --format
flag, and many of the CLI command references include examples of customizing the output format.
Note
When using the
--format
flag, you need observe your shell environment. In a POSIX shell, you can run the following with a single quote:Otherwise, in a Windows shell (for example, PowerShell), you need to use single quotes, but escape the double quotes inside the parameters as follows:
join
concatenates a list of strings to create a single string. It puts a separator between each element in the list.
table
specifies which fields you want to see its output.
json
encodes an element as a json string.
lower
transforms a string into its lowercase representation.
split
slices a string into a list of strings separated by a separator.
title
capitalizes the first character of a string.
upper
transforms a string into its uppercase representation.
pad
adds whitespace padding to a string. You can specify the number of spaces to add before and after the string.
This example adds 5 spaces before the image repository name and 10 spaces after.
truncate
shortens a string to a specified length. If the string is shorter than the specified length, it remains unchanged.
This example displays the image repository name, truncating it to the first 15 characters if it's longer.
println
prints each value on a new line.
To find out what data can be printed, show all content as json: