docker ps 过滤和格式化
https://docs.docker.com/engine/reference/commandline/ps/
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. |
"table " 显示表头
"{{.ID}}" 显示ID
"{{.Names}}" 显示NAMES
依次类推
举例(区分大小写):
"table {{.ID}}\t{{.Names}}"
Filtering
The filtering flag (-f
or --filter
) format is a key=value
pair. If there is more than one filter, then pass multiple flags (e.g. --filter "foo=bar" --filter "bif=baz"
)
The currently supported filters are:
- id (container’s id)
- label (
label=<key>
orlabel=<key>=<value>
) - name (container’s name)
- exited (int - the code of exited containers. Only useful with
--all
) -
status (created restarting running paused exited dead) - ancestor (
<image-name>[:<tag>]
,<image id>
or<image@digest>
) - filters containers that were created from the given image or a descendant. - before (container’s id or name) - filters containers created before given id or name
- since (container’s id or name) - filters containers created since given id or name
-
isolation (default process hyperv) (Windows daemon only) - volume (volume name or mount point) - filters containers that mount volumes.
- network (network id or name) - filters containers connected to the provided network