#7: Increasing the output readability of Docker's container list command
Working regularly with Docker on the command line often means running docker ps to list containers. But the output of this command can become quite
overwhelming. Especially on small screens, especially on remote terminal
sessions, especially when image or command names are quite long.
$ docker ps
CONTAINER ID IMAGE
COMMAND CREATED STATUS
PORTS NAMES
8fbf0b720857 registry.docker.evil.corp/platform-engineering/internal-tooling/l
ab/agent-daemon:latest "/entrypoint.sh" 10 days ago Up About an hou
r agent-daemon
f36f28350a72 meyay/languagetool:6.6
"/sbin/tini -g -e 14…" 4 months ago Up About an hou
r (healthy) 0.0.0.0:8081->8081/tcp, [::]:8081->8081/tcp languagetool
41679cac8b4c mcr.microsoft.com/mssql/server:2022-CU20-ubuntu-22.04
"/opt/mssql/bin/cust…" 7 months ago Up About an hou
r 0.0.0.0:1433->1433/tcp, [::]:1433->1433/tcp database
Luckily, we can format the output. But unfortunately the required Go template syntax isn't something lazy command-line users want to deal with. While changing the default output format for common Docker commands is supported1, switching between different output formats is not.
With good old aliases, we can meet this need. The following ones turned out helpful in the field and are easy to remember.
# Docker container status: docs
alias docs='docker ps --format "table {{.ID}}\t{{.Names}}\t{{.RunningFor}}\t{{.Status}}"'
# Docker container images: doci
alias doci='docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Image}}"'
# Docker container ports: docp
alias docp='docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}"'
# Docker container commands: docc
alias docc='docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Command}}"'
$ docs
CONTAINER ID NAMES CREATED STATUS
8fbf0b720857 agent-daemon 10 days ago Up About an hour
f36f28350a72 languagetool 4 months ago Up About an hour (healthy)
41679cac8b4c database 7 months ago Up About an hour
$ doci
CONTAINER ID NAMES IMAGE
8fbf0b720857 agent-daemon registry.docker.evil.corp/platform-engineering/internal-tooling/lab/agent-daemon:latest
f36f28350a72 languagetool meyay/languagetool:6.6
41679cac8b4c database mcr.microsoft.com/mssql/server:2022-CU20-ubuntu-22.04
$ docp
CONTAINER ID NAMES PORTS
8fbf0b720857 agent-daemon
f36f28350a72 languagetool 0.0.0.0:8081->8081/tcp, [::]:8081->8081/tcp
41679cac8b4c database 0.0.0.0:1433->1433/tcp, [::]:1433->1433/tcp
$ docc
CONTAINER ID NAMES COMMAND
8fbf0b720857 agent-daemon "/entrypoint.sh"
f36f28350a72 languagetool "/sbin/tini -g -e 14…"
41679cac8b4c database "/opt/mssql/bin/cust…"
See the official Docker CLI documentation for more details.↩