Home » Docker » How to List Docker Containers in Different States

How to List Docker Containers in Different States

In Docker, you can get a list of all running containers using the docker ps command. You can use the docker ps -a command to list all containers, including stopped ones.

The following examples show how to list both running Docker containers and all Docker containers, including stopped ones.

How to List Running Docker Containers Using `docker ps`

To list only the running Docker containers, we can use the docker ps command.

If we want to view all currently running Docker containers, we can run the following command in the terminal:

docker ps

Output: 👇️

show running containers
Show running containers

In this example, the docker ps command lists all running containers with details such as container ID, image, command, created, status, ports, and names.

Notice that, the docker ps command returns the app-mqtt and app-postgres containers that are running.

This helps us to monitor which containers are currently active in our Docker environment.

How to List All Docker Containers (Including Stopped) Using `docker ps -a`

To get a list of all containers, including stopped ones, we can use the docker ps -a command.

Suppose we would like to see all containers, regardless of their status.

We can use the following command in the terminal:

docker ps -a

Output: 👇️

show running and stopped containers
Show running and stopped containers

In this example, the docker ps -a command lists all containers, including those that have stopped.

In the above screenshot, containers with the names app-mqtt and app-postgres are running while the app-pgadmin container is in a stopped state. The app-pgadmin container STATUS column shows “Exited (1) 29 minutes ago”.

Conclusion

We can use the docker ps command to get a list of running containers and the docker ps -a command to get a list of all containers, including stopped ones.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.