In this tutorial, we will show you how to use Docker to list your installed containers.
Docker provides numerous tools within its runtime; one is the ability to list the containers you have installed on your system.
By listing containers, you can very quickly find the ID for each of them. You can then use these IDs to control your containers.
In addition to viewing a container’s ID, you can view several other important bits of information, including the image’s name, the command issued by the container, when it was created, and its current status.
These steps on listing Docker containers should work for all versions of Docker since 1.13. Older versions of Docker will still work, but you will need to use the older “docker ps
” alias instead.
Using the Terminal to List Docker Containers
In this guide, we will show you the various ways to list your Docker containers from within the terminal.
The Docker tool offers numerous ways to control its output and list the containers that you require.
Syntax for Listing Docker Containers
The Docker runtime makes listing all installed containers a really simple process. It also offers numerous options that allow you to control how and what containers are listed.
At its most basic usage, all you need to do is use “docker container ls
“. This will list all running containers. Any options you want to use to control the listed containers are specified after this container.
docker container ls [OPTIONS]
[OPTIONS]
: By using options, it is possible to control the list of containers that is output by the Docker command. You can even filter the results.-a
: Lists all containers that are on your system, including those that aren’t running.
By default, Docker will only list the containers that are running.-l
: Allows you to list the latest Docker container created on your system.-n NUMBER
: Using this option, you can specify the last number of containers you want listed.
For example, by specifying the number “2”, the command will list the last two created containers.-q
: This option changes the behavior of the Docker ls command to only list the IDs of containers. It is useful when you want to pipe the result into other commands.-s
: By default, when listing Docker containers this tool will not include the size of your containers. Using this option will change that behaviour.--no-trunc
: Container IDs will automatically be truncated to 12 characters. By including this option, you can get the tool to output the full ID.--filter KEY=VALUE
: You can also filter the list to only include the containers that you are after. The filter expects a key such as “name
” or “label
” and a value you are filtering for.
Default Behaviour of Listing Containers
Let us start by exploring the default way that Docker lists the available containers on your system. This will also give us a chance to walk through the data returned from this command. By default, Docker only displays the containers that are currently running.
To list running containers using Docker, use the following command within the terminal.
docker container ls
Below is an example of the data that will be returned when listing the running containers.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
159ba039236b postgres:15 "docker-entrypoint.s…" 2 weeks ago Up 4 days 5432/tcp grafana_postgres
430c5a8cccc0 grafana/grafana-enterprise:latest "/run.sh" 2 weeks ago Up 4 days 0.0.0.0:3000->3000/tcp, :::3000->3000/tcp grafana
0daf8a112257 influxdb:2 "/entrypoint.sh infl…" 5 weeks ago Up 4 days 0.0.0.0:8086->8086/tcp, :::8086->8086/tcp influxdb
01dcdbd47316 vaultwarden/server:latest "/start.sh" 6 weeks ago Up 4 days (healthy) 0.0.0.0:80->80/tcp, :::80->80/tcp, 3012/tcp vaultwarden
d2ff901178bc plexinc/pms-docker "/init" 5 months ago Up 4 days (healthy) plex
Now that you know the data returned when listing your Docker containers. Let us explore what each of the columns represents.
CONTAINER ID
: The first column contains the ID that belongs to that particular container. This IDIMAGE
: This is the name of the image that was used to create this container.COMMAND
: Here you can see the command that was used to bring the container up to a running status.
This command is typically the last command that was run, and the container manager will continue to monitor it to ensure it remains running.CREATED
: The created column lets you easily see when the Docker runtime created this particular container.STATUS
: If the container is running, the status field will tell you how long this service has been running. Additionally, if you have set a health check, it will display whether the container is healthy.
If the container his stopped, you will see how long that container has been offlinePORTS
: This column lists the ports that this Docker container has exposed on the system.NAMES
: The final value you will see when listing your Docker containers is the names assigned to each container.
Listing All Docker Containers Including Not Running
By default, Docker will only list the containers currently running on your system. Luckily, to list running containers, you only need to use the “-a
” or “--all
” options.
This will allow you to show all containers regardless of it’s status. It is useful when you
docker container ls -a
Below, you can see the same number of columns displayed. However, this time we can now see three additional Docker containers listed that aren’t currently running.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
159ba039236b postgres:15 "docker-entrypoint.s…" 2 weeks ago Up 4 days 5432/tcp grafana_postgres
430c5a8cccc0 grafana/grafana-enterprise:latest "/run.sh" 2 weeks ago Up 4 days 0.0.0.0:3000->3000/tcp, :::3000->3000/tcp grafana
1de88e0a818f seafileltd/seafile-mc:11.0-latest "/sbin/my_init -- /s…" 4 weeks ago Exited (2) 9 days ago seafile
3234711c452a memcached:1.6.18 "memcached -m 256" 4 weeks ago Exited (0) 9 days ago seafile-memcached
649e8b0a5988 mariadb:10.11 "docker-entrypoint.s…" 4 weeks ago Exited (0) 9 days ago seafile-mysql
0daf8a112257 influxdb:2 "/entrypoint.sh infl…" 5 weeks ago Up 4 days 0.0.0.0:8086->8086/tcp, :::8086->8086/tcp influxdb
01dcdbd47316 vaultwarden/server:latest "/start.sh" 6 weeks ago Up 4 days (healthy) 0.0.0.0:80->80/tcp, :::80->80/tcp, 3012/tcp vaultwarden
d2ff901178bc plexinc/pms-docker "/init" 5 months ago Up 4 days (healthy) plex
Only List the Latest Docker Container
If you are only interested in listing the latest Docker container you have set up on your system, there is one option that you may want to use.
Using the “-l
” or “--latest
” options, Docker will only list the last container that was created.
docker container ls -l
With the result below, you can see how only the latest container was included within the output.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fbc1b4e3a8bc ghcr.io/home-assistant/amd64-hassio-supervisor:latest "/init" 26 hours ago Up 26 hours hassio_supervisor
List a Specific Number of Docker Containers
Listing a specific number of containers by utilizing the “-n
” or “--last
” option is also possible.
With this option, Docker will list the number of containers you have specified. The list is ordered from newest to oldest, so specifying “2
” will show the last 2 containers that were created.
docker container ls -n NUMBER
Newest Created Containers
To give you an example of how this option works, let us list the last 3 Docker containers created on our system.
docker container ls -n 3
Below, you can see that by specifying “3
“, the last three containers were listed.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fbc1b4e3a8bc ghcr.io/home-assistant/amd64-hassio-supervisor:latest "/init" 26 hours ago Up 26 hours hassio_supervisor
61dc6244a65c ghcr.io/home-assistant/amd64-hassio-multicast:2024.03.0 "/init" 4 days ago Up 4 days hassio_multicast
41c8ca9eaf94 ghcr.io/home-assistant/amd64-hassio-audio:2023.12.0 "/init" 4 days ago Up 4 days hassio_audio
Only List Docker Container IDs by using Quiet Mode
By default, Docker includes several bits of information when listing the containers on your system. However, there are many cases where you will likely only want the container ID.
The container ID is super important as it is what you will use to control a specific container on your system. For example, you will want to use a container ID when tailing the logs of a specific container.
You can use the “-q
” or “--quiet
” options to get Docker to only output the ID of each container.
docker container ls -q
Below, you can see the ID of each running container output to the terminal.
fbc1b4e3a8bc
61dc6244a65c
41c8ca9eaf94
15b9857d91e0
685dc0c5df27
159ba039236b
430c5a8cccc0
0daf8a112257
01dcdbd47316
d2ff901178bc
51069b675022
303cece0604f
List Docker Containers with their Total Size
One potentially key piece of information that is not included when you use Docker to list containers is the file size. Luckily, Docker includes an option to output the size of a container. With this output, you will see the size of the writable layer and the size of the read-only image this container is using.
To get Docker to output the size of your containers, you must use the “-s
” or “--size
” option.
docker container ls -s
Below is an example of how the output would look after outputting the size of your containers.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES SIZE
fbc1b4e3a8bc ghcr.io/home-assistant/amd64-hassio-supervisor:latest "/init" 26 hours ago Up 26 hours hassio_supervisor 15.4kB (virtual 337MB)
With this output, you can see that the only new piece of data is in the “Size
” column.
- The first value you see represents the size of the writeable layer of the image.
- The second value included within the brackets is the size of the image that this container is running off of.
15.4kB (virtual 337MB)
Don’t Truncate Docker ID’s
The ID returned by Docker when listing your containers is automatically truncated to 12 characters by default. You only need these 12 characters when interacting with your containers, but the full ID is significantly longer.
A Docker container ID is actually a unique 64-character long hexadecimal string.
You can get Docker not to truncate the ID when listing your containers by including the “--no-trunc
” option.
docker container ls --no-trunc
Looking at the result below, you can see the significantly longer IDs that are now output.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fbc1b4e3a8bc5fe83cd7470b2d24d311e2c6205904f1a24f7d2176f77164f258 ghcr.io/home-assistant/amd64-hassio-supervisor:latest "/init" 26 hours ago Up 26 hours hassio_supervisor
61dc6244a65c17830d51c7f43503eae28e544b487a249bc140aeb6c2231e4f28 ghcr.io/home-assistant/amd64-hassio-multicast:2024.03.0 "/init" 4 days ago Up 4 days hassio_multicast
Conclusion
At this point in the tutorial, you should have a good understanding of how you can list the Docker containers on your system.
Listing the containers running on your system allows you to easily see what is running and what isn’t and also get the IDs needed to control your containers. We have shown you many different ways to use this tool.
Please feel free to comment below if you have any questions or issues with listing the Docker containers on your system.
If you liked this guide, we highly recommend you check out the many other Docker guides we offer.