Docker

How to List Docker Containers

Docker is a popular open-source platform due to its containerization concept. It is used for building and deploying projects. For this purpose, it utilizes Docker images, Docker registries, and Docker containers. Docker containers are the essential part of Docker used to manage, build, and run projects along with their dependencies.

This write-up will illustrate how to list Docker Containers.

How to List Docker Containers?

Sometimes developers or administrative users are required to view containers or check container size or status. For this purpose, you can list down Docker containers using the listed methods:

Method 1: List All Docker Containers

To list all Docker containers users can use the “docker container ls” command along with the “-a” option. If the user does not use the “-a” option, then the provided command will show only running containers:

> docker container ls -a

Alternatively, the “docker ps” command is also used to show all containers:

> docker ps -a

Method 2: List Docker Containers With Size

In order to list down Docker containers as well as their size, the “-s” option is utilized along with the “docker ps” command:

> docker ps -a -s

Method 3: List Latest Containers

Users can also view only the latest created containers with the help of the “-l” option as shown below:

> docker ps -a -l

Method 4: List All Containers by Id

In order to list view only container id or list down Docker container in quiet mode, utilize the “-q” option along with mentioned command:

> docker ps -a -q

Method 5: List Container in Specific Format

Docker users can also list down Docker containers in a format specified using the “–format” option. For instance, we have listed down only container ids and container names:

> docker ps -a --format "{{.ID}}: {{.Names}}"

Alternatively, users can also view the container in a specific format in the form of a table with the help of the given command:

> docker ps -a --format "table {{.ID}}\t{{.Names}}"

That was all about listing Docker containers.

Conclusion

To list down the Docker containers users can either use the “docker container ls” command or the “docker ps -a” command. These commands also support different options to list containers in different ways, such as “-a” is used to list all containers, “-q” is used to list only container ids, and “–format” is utilized to list containers in a specific format. This write-up has demonstrated how to list Docker containers.

About the author

Rafia Zafar

I am graduated in computer science. I am a junior technical author here and passionate about Programming and learning new technologies. I have worked in JAVA, HTML 5, CSS3, Bootstrap, and PHP.