Get List of Docker Containers

Get List of Docker Containers

Docker provides a way to package and run an application in a container. When working with Docker containers, then you may need to get a list of containers. This tutorial demonstrates how to do that.

Get list of containers

To get a list of running containers, use docker ps command or docker container command with ls argument:

docker ps
docker container ls

Output example:

CONTAINER ID   IMAGE     COMMAND                  CREATED       STATUS       PORTS      NAMES
6cd2789fb495   nginx     "/docker-entrypoint.…"   3 hours ago   Up 3 hours   80/tcp     nginx
a1f34c45490d   redis     "docker-entrypoint.s…"   3 hours ago   Up 3 hours   6379/tcp   redis

Note that, only the header line is displayed, if there are no running containers. To get a list of all containers, use -a or --all option:

docker ps -a
docker container ls -a

Output example:

CONTAINER ID   IMAGE     COMMAND                  CREATED       STATUS                   PORTS      NAMES
b15fd2927844   ubuntu    "/bin/bash"              3 hours ago   Exited (0) 3 hours ago              ubuntu
6cd2789fb495   nginx     "/docker-entrypoint.…"   3 hours ago   Up 3 hours               80/tcp     nginx
a1f34c45490d   redis     "docker-entrypoint.s…"   3 hours ago   Up 3 hours               6379/tcp   redis

Get list of containers with full length IDs

By default, container IDs are truncated. The --no-trunc option can be used to show not truncated output:

docker ps --no-trunc
docker container ls --no-trunc

Output example:

CONTAINER ID                                                       IMAGE     COMMAND                                          CREATED       STATUS       PORTS      NAMES
6cd2789fb49582c9ebc8ee767d727998bb776afb48b7e9c7c9f16c8cc7312b61   nginx     "/docker-entrypoint.sh nginx -g 'daemon off;'"   3 hours ago   Up 3 hours   80/tcp     nginx
a1f34c45490d924debb2b285e663220092f82e12b9ffb82c949e2db11cb701d4   redis     "docker-entrypoint.sh redis-server"              3 hours ago   Up 3 hours   6379/tcp   redis

Get only IDs of containers

To display only IDs of containers, use -q or --quiet option:

docker ps -q
docker container ls -q

Output example:

6cd2789fb495
a1f34c45490d

Get size of containers

Use the -s or --size option to view the size of the containers:

docker ps -s
docker container ls -s

Output example:

CONTAINER ID   IMAGE     COMMAND                  CREATED       STATUS       PORTS      NAMES     SIZE
6cd2789fb495   nginx     "/docker-entrypoint.…"   3 hours ago   Up 3 hours   80/tcp     nginx     1.09kB (virtual 142MB)
a1f34c45490d   redis     "docker-entrypoint.s…"   3 hours ago   Up 3 hours   6379/tcp   redis     0B (virtual 117MB)

Leave a Comment

Cancel reply

Your email address will not be published.