Formatting
$ cat config.json { "auths": { "git.agis.kz:5040": { "auth": "**************************************" } }, "HttpHeaders": { "User-Agent": "Docker-Client/19.03.12 (linux)" }, "psFormat": "table {{.Names}}\\t{{.Mounts}}\\t{{.Ports}}" }
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. |
.State | Container status (for example; “created”, “running”, “exited”). |
.Status | Container status with details about duration and health-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
and Command
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
Фильтрация
$ docker ps -a --format='{{.Names}}' | grep lb lb-billing-facade-billing-prod-srvkzowc-kzowc lb-address-service-billing-prod-srvkzowc-kzowc lb-i18n-service-billing-prod-srvkzowc-kzowc lb-tariff-service-billing-prod-srvkzowc-kzowc lb-fs-service-billing-prod-srvkzowc-kzowc lb-document-service-billing-prod-srvkzowc-kzowc lb-identity-service-billing-prod-srvkzowc-kzowc lb-reference-service-billing-prod-srvkzowc-kzowc lb-period-service-billing-prod-srvkzowc-kzowc lb-counter-service-billing-prod-srvkzowc-kzowc lb-report-service-billing-prod-srvkzowc-kzowc lb-accounting-service-billing-prod-srvkzowc-kzowc lb-client-service-billing-prod-srvkzowc-kzowc lb-billing-service-tmp-srvkzowc-kzowc $ docker ps -a --format='{{.Names}}' | grep lb | xargs docker inspect --format='{{.Mounts}}' [{bind /data/docker/billing/config-facade /src/config true rprivate}] [{bind /data/docker/billing-prod-srvkzowc-kzowc/config /lb-address-service/config true rprivate}] [{bind /data/docker/billing-prod-srvkzowc-kzowc/config /lb-i18n-service/config true rprivate}] [{bind /data/docker/billing-prod-srvkzowc-kzowc/config /lb-tariff-service/config true rprivate}] [{bind /data/docker/billing-prod-srvkzowc-kzowc/config /lb-fs-service/config true rprivate}] [{bind /data/docker/billing-prod-srvkzowc-kzowc/config /lb-document-service/config true rprivate}] [{bind /data/docker/billing-prod-srvkzowc-kzowc/config /lb-identity-service/config true rprivate}] [{bind /data/docker/billing-prod-srvkzowc-kzowc/config /lb-reference-service/config true rprivate}] [{bind /data/docker/billing-prod-srvkzowc-kzowc/config /lb-period-service/config true rprivate}] [{bind /data/docker/billing-prod-srvkzowc-kzowc/config /lb-counter-service/config true rprivate}] [{bind /data/docker/billing-prod-srvkzowc-kzowc/config /lb-report-service/config true rprivate}] [{bind /data/docker/billing-prod-srvkzowc-kzowc/config /lb-accounting-service/config true rprivate}] [{bind /data/docker/billing-prod-srvkzowc-kzowc/config /lb-client-service/config true rprivate}] [{bind /data/docker/lb-billing-service-tmp/config /src/config true rprivate}]