'docker ps' output is too wide - how to hide columns
Posted in how to on May 19, 2020 ‐ 2 min read
I’ve been using docker a lot more often lately, and have many containers that have long image names and a large number of ports used. This results in the docker ps -a
output being entirely too wide even on my high resolutions screens which can make it difficult to read. In general I only care about a few columns and I’d prefer to limit my output to just those columns.
Format option
The docker ps command supports an option called --format
that allows you to “Pretty-print containers using a Go template”.
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. I like to see the table headers so I include table.
Example
To get a list of all running containers with just their IDs and labels you would 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
Check the docker ps documentation to find the different column header names that can be used.
I personally like to see all containers with just their name, image, and status by using $ docker ps -a --format="table {{.Names}}\t{{.Image}}\t{{.Status}}"
.
Alias
To prevent having to constantly type that command over and over, you can easily add this as a bash alias such as alias dpsa='docker ps -a --format="table {{.Names}}\t{{.Image}}\t{{.Status}}"'
.