Formatting
The formatting option (
--format
) pretty-prints container output using a Go template.
Valid placeholders for the Go template are listed below:
Placeholder | Description |
---|---|
.ID | Container ID |
.Image | Image ID |
.Command | Quoted command |
.CreatedAt | Time when the container was created. |
.RunningFor | Elapsed time since the container was started. |
.Ports | Exposed ports. |
.Status | Container status. |
.Size | Container disk size. |
.Names | Container names. |
.Labels | All labels assigned to the container. |
.Label | Value of a specific label for this container. For example '{{.Label "com.docker.swarm.cpu"}}' |
.Mounts | Names of the volumes mounted in this container. |
.Networks | Names of the networks attached to this container. |
When using the
--format
option, the ps
command will either output the data exactly as the template declares or, when using the table
directive, includes column headers as well.
The following example uses a template without headers and outputs the
ID
andCommand
entries separated by a colon for all running containers:$ docker ps --format "{{.ID}}: {{.Command}}"
a87ecb4f327c: /bin/sh -c #(nop) MA
01946d9d34d8: /bin/sh -c #(nop) MA
c1d3b0166030: /bin/sh -c yum -y up
41d50ecd2f57: /bin/sh -c #(nop) MA
To list all running containers with their labels in a table format you can use:
$ docker ps --format "table {{.ID}}\t{{.Labels}}"
CONTAINER ID LABELS
a87ecb4f327c com.docker.swarm.node=ubuntu,com.docker.swarm.storage=ssd
01946d9d34d8
c1d3b0166030 com.docker.swarm.node=debian,com.docker.swarm.cpu=6
41d50ecd2f57 com.docker.swarm.node=fedora,com.docker.swarm.cpu=3,com.docker.swarm.storage=ssd
留言
張貼留言