How to fit docker ps in your screen
Introduction
Something that has bugged me for a long time is how the command docker ps represents in my terminal:

As you can see, the output is split between several lines because it does not fit in my screen, and it makes the output super hard to read.
The solution
Hopefully, docker implemented a solution that allows us to configure this command as we like.
-
Just open your
config.json:nano .docker/config.jsonℹ️ If you don’t have a
config.jsonyet, this command will create it. -
Add the following config to it:
"psFormat": "table {{.ID}}\t{{.Image | printf \"%.20s\"}}\t{{.State}}\t{{.Status}}\t{{.Names}}"So that your config looks like this:
{ ...whatever you had before..., "psFormat": "table {{.ID}}\t{{.Image | printf \"%.20s\"}}\t{{.State}}\t{{.Status}}\t{{.Names}}" } -
Now your
docker psoutput looks so much better!

What does this line do and further configuration
Lets analize this code:
"psFormat": "table {{.ID}}\t{{.Image | printf \"%.20s\"}}\t{{.State}}\t{{.Status}}\t{{.Names}}"
Here we say:
table {{.ID}}-> Show the ID of the containers{{.Image | printf \"%.20s\"}}-> Show the image name truncated to 20 characters{{.State}}-> Show the state of the containers{{.Status}}-> Show the status of the containers{{.Names}}-> Show the containers’ names
You can customize this however you want, by adding or removing parameters such as:
Container identification
{{.ID}} -> Container ID (short)
{{.Image}} -> Image name
{{.Names}} -> Container name
Runtime / state
{{.Command}} -> Command used to run the container
{{.CreatedAt}} -> Created timestamp (formatted)
{{.RunningFor}} -> Time since creation (human readable)
{{.State}} -> State (created, running, exited…)
{{.Status}} -> Full status (e.g., “Up 5 minutes”)
{{.Ports}} -> Port mappings
Resources & metadata
{{.Size}} -> Size information
{{.Mounts}} -> Mounted volumes
Labels
{{.Labels}} -> All labels
{{.Label "key"}} -> A specific label, e.g. {{.Label "traefik.enable"}}
Networks
{{.Networks}} -> Networks the container is attached to
As you can see, there’s a lot of info we can show and format in our own way to make the docker ps command much more practical.