by Devin Yang
(This article was automatically translated.)

Published - 1 year ago ( Updated - 1 year ago )

I think if you want to write some automation functions, it may be useful to be able to format the output container content.
The following are some reference examples of Docker container formatting and display commands

docker ps --format "{{.ID}}\t{{.Names} }"
#For example, the name and command to execute
docker ps --format "table {{.Names}}: {{.Command}}" --no-trunc
#If there is a table, it will contain the field name
docker ps --filter volume=/data --format "table {{.ID}}\t{{.Mounts}}" --no-trunc
#If Docker swarm mode can also be used
docker service ls --format "table {{.Name}}\t{{.Ports}}"

Format

Format option (--format ) to pretty print container output using Go templates.
The valid placeholders for Go templates are listed below:

placeholderdescription< /th>
.IDContainer ID
. ImageImage ID
.CommandQuoted command
.CreatedAtTime when the container was created.
.RunningFor from the container Elapsed time since startup. (Elapsed time since the container was started.)
.PortsExposed ports.
.StateContainer state. Container status (for example; “created”, “running”, “exited”).
.StatusContainer status, including information about duration and Details of the health status. Container status with details about duration and health-status.
.SizeContainer disk size. Container disk size.
.NamesContainer name. Container names.
.LabelsAll labels assigned to the container. All labels assigned to the container.
.LabelThe value of a specific label for this container. For example '{{.Label "com.docker.swarm.cpu"}}'.
Value of a specific label for this container. For example '{{.Label "com.docker.swarm.cpu"}}'
.MountsThe name of the volume mounted in this container. Names of the volumes mounted in this container.
.NetworksThe names of the networks attached to this container. Names of the networks attached to this container.

Tags: docker cli

Devin Yang

Feel free to ask me, if you don't get it.:)

No Comment

Post your comment

Login is required to leave comments

Similar Stories


docker,laravel

How to use multiple YAML files to execute multiple docker container services

This video introduces how to use the docker-compose command to specify multiple YAML structure language configuration files to create container execution, and introduces how we simplify docker-compose by using .env in the D-Laravel environment Start command.

docker

How to update or rebuild D-Laravel's FPM Image

Sometimes, the docker image will undergo some corrections or add more plug-ins, how do we update the image in the computer? It's very simple, use docker pull [use the image], if you want to create your own image is also feasible...

docker,polymer,seo

Solving Polymer SEO Problems with Rendertron (Polymer Summit 2017)

The video below the article introduces how to use rendertron to solve Polymer SEO optimization problems. In the source of my fork, it has been adjusted to support the Chinese environment. And also added the API interface of pdf, which can also be used to convert pdf.