How to List Docker Containers With Pretty Formatting

In Docker on 1~3 minutes
How to List Docker Containers With Pretty Formatting

When we develop and deploy applications with Docker, often we need to check the statuses of our containers. Mainly we can use either docker ps (Docker Process Status) or docker container ls (Docker Container List) commands for that. Both commands show the same information and all the additional options mentioned in this question are interchangeable between the two commands. Additionally, docker container ls is the newest one and it is introduced in Docker 1.13.

Show Currently Running Containers

Following commands will only show currently running containers.

docker ps

or

docker container ls

Show All Running And Stopped Containers

We can add the -a or --all option to list all the containers in created, restarting, running, removing, paused, exited, or dead statuses.

docker container ls -a

Show Running Containers With Pretty-Print Formatting

The common problem with previous commands is, all of them show information without any formatting. But fortunately, we can format them with the --format option.

docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Networks}}\t{{.State}}\t{{.CreatedAt}}"

Now it will nicely display everything like below.

CONTAINER ID   NAMES        NETWORKS  STATE     CREATED AT
61ed230v9632   laravelApp   laravel   running   2021-10-16 14:52:20 +0000 +0000
d93c7d6fjf39   mysql        laravel   running   2021-10-16 14:52:19 +0000 +0000
7fe3eq1ja2he   phpMyAdmin   bridge    running   2021-06-29 22:18:10 +0000 +0000

Show All Containers With Pretty-Print Formatting

As usual, we can use the -a option to display all containers with all the statuses.

docker ps -a --format "table {{.ID}}\t{{.Names}}\t{{.Networks}}\t{{.State}}\t{{.CreatedAt}}"

Visit the official Docker documentation for more available placeholders to view ports, sizes, labels, mounts, networks and more.