brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: docker ps --format table gives you a readable overview

Docker
~/tips/tip-docker-ps-format

docker ps --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}'

Lists running containers with only the columns you choose, such as name and status.

The default docker ps output is wide. On a normal terminal it wraps, and the one column you care about ends up on the next line.

You pick the columns yourself with a Go template. Start the template with table to get headers.

docker ps --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}'

That gives you three tidy columns: name, status and ports. Add -a to include stopped containers. Not sure which fields exist? Run docker ps --format '{{json .}}' once and read the keys of the first line.

To make it permanent, there is a psFormat setting in the Docker CLI config file, ~/.docker/config.json. I would put the template there once and forget about it.

Names and statuses are the pair I look at most. The status column shows how long a container has been up, and whether it is healthy, which is a quick way to notice one that keeps restarting.

The caveat: the \t has to reach Docker as a literal backslash and t, so keep the template in single quotes. And a fixed set of columns hides things you may need later, like the image name, so keep the full command in mind.

Further reading: Format command and log output, On this site: docker inspect –format pulls one value out of the wall of JSON, On this site: docker diff shows what a container changed in its filesystem

More Docker tips ONBUILD RUN /usr/local/bin/python-build --dir /app/src SHELL ["/bin/bash", "-c"] docker commit <container> myname/testimage:version3 docker import /path/to/exampleimage.tgz docker compose events All Docker tips (192) All topics

Link