How To List Docker Containers?

Docker is a popular containerization tool. By using docker a lot of containers can be created easily in a short time. But one of the most popular problems is how can be list docker containers. A docker container can be in different states like running, stopping, etc. In this tutorial, we examine how to list docker containers.

List Only Running Containers

The docker provides docker ps command in order to list only running containers.

$ docker ps

List Only Stopped Containers

By default the docker ps command only lists running containers. But there may be stopped or exited containers. These containers can be listed with the --filter='status=exited' option. The status=exited is used to express the status of the docker containers.

$ docker ps --filter='status=exited'
List All Containers

Alternatively the short form of the –filter option -f can be used to list all containers.

$ docker ps --f='status=exited'

List All Containers

The -a option can be used to list all running and stopped containers.

$ docker ps -a
List All Containers

List Latest Created Containers

The -l option can be used to list latest created containers according to the creation time. These containers can becurrently running or exited.

$ docker ps -l

Remove All Not Running Containers

The following command can be used to remove all running containers.

$ docker rm 'docker ps -aq -f status=exited'
See also  How To Change Ubuntu Hostname?

Leave a Comment