How to show specific column with docker ps command
Refs
Prerequisite
- jq command
First Example
# docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Status}}"
CONTAINER ID NAMES STATUS
6649ac512517 jupyter-notebook Up 15 hours (healthy)
adc3f126a364 cadvisor Up 3 weeks (healthy)
45c106f51a6e mailserver Up 3 weeks (healthy)
f34501c9a42e docker_exporter Up 32 hours
What column name is available?
- Get available column names with json key name!
# docker container ls --format='{{json .}}' | jq -rcs '.[0] | keys[]'
Command
CreatedAt
ID
Image
Labels
LocalVolumes
Mounts
Names
Networks
Ports
RunningFor
Size
State
Status
Second Examples
# docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Size}}"
CONTAINER ID NAMES STATUS SIZE
6649ac512517 jupyter-notebook Up 15 hours (healthy) 3.27MB (virtual 4.41GB)
adc3f126a364 cadvisor Up 3 weeks (healthy) 0B (virtual 80.8MB)
45c106f51a6e mailserver Up 3 weeks (healthy) 764kB (virtual 629MB)
f34501c9a42e docker_exporter Up 32 hours 0B (virtual 57.2MB)
# docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Image}}\t{{.Size}}"
CONTAINER ID NAMES STATUS IMAGE
6649ac512517 jupyter-notebook Up 15 hours (healthy) jupyter_20240419/scipy-notebook:2023-08-19
adc3f126a364 cadvisor Up 3 weeks (healthy) gcr.io/cadvisor/cadvisor:v0.49.1
45c106f51a6e mailserver Up 3 weeks (healthy) ghcr.io/docker-mailserver/docker-mailserver:latest
f34501c9a42e docker_exporter Up 32 hours prometheusnet/docker_exporter
# docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}"
# docker ps --no-trunc --format "table {{.Names}}\t{{.Mounts}}"
NAMES MOUNTS
pihole /root/docker-compose/etc-dnsmasq.d,/root/docker-compose/etc-pihole
postgres_na24.2 /docker-postgres/na24.2/data
postgres_na23.4 /docker-postgres/na23.4/data
postgres_oo24.1 /docker-postgres/oo24.1/data
jupyter-notebook
jira2 jiraVolume
cadvisor /var/lib/docker,/var/run,/dev/disk,/,/sys
mailserver /etc/localtime,/docker-data/dms/config,/docker-data/dms/mail-logs,/docker-data/dms/mail-data,/docker-data/dms/mail-state