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

How to simply use Docker to create an internet command line speed test program?

How to simply use Docker to create an internet command line speed test program? Here we use the python program speedtest-cli Will use Docker for the main use case, for example, I want to test the speed in my NAS, Although there is python in my NAS, but there is no pip command, it feels much safer to use Docker at this time. Of course, your NAS needs to be able to run Docker :). Or, I am in a MacOS environment, and I don't want to install speedtest-cli into my MacOS. At this time, it is not bad to use Docker to build a simple execution environment by yourself.

docker,phpenv

Unable to ping host.docker.internal on Linux

You can check with docker version, confirm that the version is Docker v20.10+, you can add extra_hosts as follows:

dlaravel,docker

D-Laravel learning three stages

Chat about the three stages of using D-Laravel, why use D-Laravel. Because the configuration files used by D-Laravel are quite simple, it is very suitable for beginners of Docker to learn, And users who do not know how to use Docker can also use the two commands ./console and ./create to create a project.