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

Devin Yang's Notes for Beginners with Docker

These are my notes when I first learned Docker. It is a bit rough and I have adjusted it a bit. But I think for Docker beginners, it should be able to provide some preliminary concepts, Welcome to refer to it.

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

certbot,docker,ftp

curlftpfs introduction and manual certificate application

Situation sharing, imagine that you have WebHosting, which only provides FTP connection, and then you want to apply for a certificate manually. In this article, I share how I use Docker to install curlftpfs, mount the FTP folder of the remote host, and then execute certbot in the container to apply for an SSL certificate. Leaving aside the certificate application, when I first discovered the curlftpfs command, I found it very interesting, especially if you are a MacOS user and do not have a satisfactory FTP software at hand. You love scrolling through the command line as much as I do, so maybe you should love this command too. 🤭