Linuxhit

How to list Docker containers on Linux

Docker Logo

Introduction to listing Docker containers on Linux

This article explains how to list Docker containers on Linux. Docker is the most popular container stack today for development. Docker does run on Windows. However most Docker users run Linux. Listing the containers and viewing status of Docker containers is an essential troubleshooting step. Listing the Docker containers tells you if the container is running and provides with the container id and name so you can launch a shell if needed. If you want to install Docker to run containers see our installation post for Ubuntu.

List running Docker containers on Linux

First lets list only the running docker containers on your system. You will not see any stopped containers. Type the following command:

sudo docker ps

We prepend the docker ps command with sudo. Sudo gives us the access needed to access the socket for the Docker daemon. The docker command is the primary command for interacting with docker from the cli. The ps argument tells docker we want a list of running containers. This is similar to the ps command in Linux to see running processes.

All running containers will be listed similar to the screenshot below.

List all Docker containers on Linux running or stopped

To list all containers; running and stopped, run the command sudo docker ps -a

sudo docker ps -a

If you have stopped containers they will now show up in the list.

Other useful options for the docker ps command

To only list the docker containers IDs, use the command sudo docker ps -aq.

sudo docker ps -aq

Want to see only the last created container? Use sudo docker ps -l.

docker ps -l

How to troubleshoot with the docker ps command

Containers provide many benefits. However containerization adds a layer of abstraction which makes troubleshooting problems more complex. When faced with a misbehaving container workload, docker ps is the first command I go to. Before I do anything I check the container is running. If the container is not running, I list all containers. Is my container stopped? If the container is stopped I move on to debugging why the container stopped. If the container is running I know to start looking inside the container and logs for clues.

Further reading on Docker

To explore Docker further we suggest the following books: