Docker

How to list docker containers

As you know, Docker is an echo system where you can create or run containers. It is an absolutely free and open-source tool that makes it simpler for you to create, deploy and run your applications using the containers. Containers are small and lightweight alternatives to Virtual Machines that use the host operating system. It allows you to run your application in an isolated environment.

If you are a system administrator and responsible for managing Docker, then you may need to know how to list Docker containers. There are several ways to list Docker containers in Linux.

In this tutorial, we will show you how to list Docker containers with several examples.

List All Docker Containers

If you want to list all Docker containers in your system, including running Docker container and stopped Docker containers, there are several commands you can list them as shown below:

docker container list -a

Or

docker container ls -a

Or

docker container ps -a

Or

docker ps -a

You should see all running and stopped Docker containers in the following output:

CONTAINER ID     IMAGE                              COMMAND                  CREATED           STATUS                          PORTS                    NAMES
592b9fe9f478     drupal                             "docker-php-entrypoi…"   3 minutes ago     Exited (0) About a minute ago                            mystifying_cartwright
9392aab37f99     wordpress                          "docker-entrypoint.s…"   5 minutes ago     Up 5 minutes                    0.0.0.0:8081->80/tcp     wpcontainer
bcbc64840b0a     mariadb                            "docker-entrypoint.s…"   6 minutes ago     Up 6 minutes                    3306/tcp                 wordpressdb
3e5cddafb61d     technosoft2000/calibre-web:v1.1.9  "/bin/bash -c /init/…"   19 hours ago      Up 19 hours                     0.0.0.0:8082->8083/tcp   calibre-web
[/cc
<h3>A brief explanation of each column is shown below:</h3>
<strong>Container ID:</strong> A unique identification of the container.
<strong>Imag:</strong> Docker image name that used to create the container.
<strong>Command:</strong> The name of the command that runs after starting the container.
<strong>Created:</strong> Display container creation time.
<strong>Status:</strong> Display the running status of the container.
<strong>Ports: </strong>Shows the open port.
<strong>Names:</strong> Container name.

If you want to list only stopped Docker containers in your system, run the following command:
[cc lang="bash" width="700" escaped="true"]
docker ps --filter "status=exited"

You should see the following output:

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
592b9fe9f478 drupal "docker-php-entrypoi…" 4 minutes ago Exited (0)
About a minute ago mystifying_cartwright

List All Running Docker Containers

If you want to list only running Docker containers in your system, there are several commands to list them.

To list all Running Docker containers, run one of the following commands:

docker container ls

Or

docker container list

Or

docker container ps

Or

docker ps

You should see all running Docker containers in the following output:

CONTAINER ID    IMAGE                               COMMAND                  CREATED             STATUS            PORTS                    NAMES
9392aab37f99    wordpress                           "docker-entrypoint.s…"   6 minutes ago       Up 6 minutes      0.0.0.0:8081->80/tcp     wpcontainer
bcbc64840b0a    mariadb                             "docker-entrypoint.s…"   7 minutes ago       Up 7 minutes      3306/tcp                 wordpressdb
3e5cddafb61d    technosoft2000/calibre-web:v1.1.9   "/bin/bash -c /init/…"   19 hours ago        Up 19 hours       0.0.0.0:8082->8083/tcp   calibre-web

If you want to list the only ID of the running Docker container, run the following command:

docker container ls -q

You should see the following output:

9392aab37f99
bcbc64840b0a
3e5cddafb61d

List All Docker Containers by Size

You can also list all running Docker container with the size of each container

For example, list and view the size of the all running Docker containers, run the following command:

docker container list -s

You should see all running Docker containers with size column, as shown below:

CONTAINER ID    IMAGE                               COMMAND                  CREATED             STATUS           PORTS                    NAMES            SIZE
9392aab37f99    wordpress                           "docker-entrypoint.s…"   7 minutes ago       Up 7 minutes     0.0.0.0:8081->80/tcp     wpcontainer      2B (virtual 543MB)
bcbc64840b0a    mariadb                             "docker-entrypoint.s…"   7 minutes ago       Up 7 minutes     3306/tcp                 wordpressdb      2B (virtual 407MB)
3e5cddafb61d    technosoft2000/calibre-web:v1.1.9   "/bin/bash -c /init/…"   19 hours ago        Up 19 hours      0.0.0.0:8082->8083/tcp   calibre-web      103MB (virtual 406MB)

You can also list and view the size of the all running and stopped containers with the following command:

docker container ls -as

You should see the following output:

CONTAINER ID   IMAGE                               COMMAND                  CREATED           STATUS                     PORTS                    NAMES                   SIZE
592b9fe9f478   drupal                              "docker-php-entrypoi…"   5 minutes ago     Exited (0) 3 minutes ago                            mystifying_cartwright   0B (virtual 495MB)
9392aab37f99   wordpress                           "docker-entrypoint.s…"   7 minutes ago     Up 7 minutes               0.0.0.0:8081->80/tcp     wpcontainer             2B (virtual 543MB)
bcbc64840b0a   mariadb                             "docker-entrypoint.s…"   8 minutes ago     Up 8 minutes               3306/tcp                 wordpressdb             2B (virtual 407MB)
3e5cddafb61d   technosoft2000/calibre-web:v1.1.9   "/bin/bash -c /init/…"   19 hours ago      Up 19 hours                0.0.0.0:8082->8083/tcp   calibre-web             103MB (virtual 406MB

Conclusion

In this guide, you learned about how to list Docker containers with several methods. I hope you have now enough knowledge of how to list Docker containers in Linux.

About the author

Hitesh Jethva

Hitesh Jethva

I am Hitesh Jethva lives in Ahmedabad, INDIA. I am Linux system administrator and Technical writer.

I felt in love with Linux while i was started to learn Linux. I am a fan of open source technology and have more than 8+ years of experience in Linux and Open Source technologies. My main motto is to make uncomplicated things easier.

I have extensive experience within the following areas: CentOS/RHEL/FreeBSD/Ubuntu/Debian, cPanel/WHM, High Availability Architecture, Proactive security/Web Application Security, Amazon Web Services (AWS), Apache/Nginx, OpenLDAP, DevOps automation: Chef/Docker.

My expertise includes Linux system administration, installation, configuration, tuning, security and troubleshooting. I have large skills in configuring/management/support of Apache, Nginx, MariaDB, MongoDB, PHP-FPM, Nagios, Zabbix, Graylg, Redis, Docker and much more.