Original link: https://chegva.com/5716.html
Docker uses Go templates, which you can use to manipulate the output format of certain commands and log drivers.
Docker provides a basic set of 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 CLI command references include examples of custom output formats.
You need to watch your shell environment when using the –format flag. In a Posix shell, you can use single quotes to run the following command:
docker inspect –format ”
Otherwise, in Windows shells (such as PowerShell), you need to use single quotes, but escape double quotes in params, like so:
docker inspect –format “
Formatting options (–format)
.ID Container ID
.Image Image ID
.Command Quoted command
.CreatedAt The time when the container was created.
.RunningFor The elapsed time since the container was created.
.Ports exposed ports.
.Status Container status.
.Size Container takes up hard disk size.
.Names container name.
.Labels All labels of the container.
.Label specifies the value of the label such as ”
.Mounts The name of the data volume mounted to this container
join
join joins lists of strings to create a single string. It places a separator between each element in the list.
docker inspect –format “container
table
table specifies the fields whose output is to be viewed.
docker image list –format “table \t\t\t”
JSON
json encodes the element as a json string.
docker inspect –format “container
lower
lower converts the string to its lowercase representation.
docker inspect –format “” container
split
split slices a string into a list of strings separated by a delimiter.
docker inspect –format ”
title
title Capitalizes the first character of the string.
docker inspect –format “” container
upper
upper converts a string to its uppercase representation.
docker inspect –format “” container
println
println prints each value on a new line.
docker inspect –format=”container
hint
To find out what data can be printed, display everything as json:
docker container ls –format=”
Can also be displayed as a table:
docker ps –format “table\t\t”
refer to:
-
Cloud computing core technology Docker tutorial: Docker formatting commands and log output
-
Docker –format formatted output summary operation instructions
This article is transferred from: https://chegva.com/5716.html
This site is only for collection, and the copyright belongs to the original author.