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,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.

docker,laravel,nfs

Docker's NFS on macOS

D-laravel's nfs mode, in this article you can learn how to use NFS+Docker on macOS.

docker

How to start HAProxy with Docker on Raspberry

Raspberry is very cheap and has quite a lot of applications, for example, some people use it as a Wi-Fi router, For game consoles, monitors and many other IoT-related applications, I use it as a HAProxy. Long story short, since I have an old Windows server running old versions of PHP and Apache, and can't set up HTTPS certificates, I wanted to say Help through HAProxy. Let this old server also have https URL, So to share my docker-compose.yml configuration.