List containers in Docker
The docker container ls or docker ps command lists all running Docker containers, with flags like -a to show all containers including stopped ones.
Lesson Content
The docker container ls
command lists out all running containers:
$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1a2e8f9de9b4 nginx:1.27-alpine "/docker-entrypoint.…" 3 hours ago Up 3 hours 0.0.0.0:8000->80/tcp, [::]:8000->80/tcp nginx-dev
3050d0a5f901 codex-phpfpm:dev "docker-php-entrypoi…" 3 hours ago Up 3 hours 9000/tcp phpfpm-dev
78c9101c6d5d bitnami/pgbouncer:latest "/opt/bitnami/script…" 3 hours ago Up 3 hours 0.0.0.0:6432->6432/tcp, [::]:6432->6432/tcp pgbouncer
236c919071c1 pgvector/pgvector:pg17 "docker-entrypoint.s…" 3 hours ago Up 3 hours 0.0.0.0:5432->5432/tcp, [::]:5432->5432/tcp postgresql
965ce015468e redis:7.4-alpine "docker-entrypoint.s…" 3 hours ago Up 3 hours 0.0.0.0:6379->6379/tcp, [::]:6379->6379/tcp redis
93137d8beb17 codex-node "docker-entrypoint.s…" 3 hours ago Up 3 hours 0.0.0.0:5173->5173/tcp, [::]:5173->5173/tcp codex-node-1
de9433010a10 axllent/mailpit:v1.22 "/mailpit" 3 hours ago Up 3 hours (healthy) 0.0.0.0:1025->1025/tcp, [::]:1025->1025/tcp, 0.0.0.0:8025->8025/tcp, [::]:8025->8025/tcp, 1110/tcp codex-mailpit-1
8a2abaec8c93 traefik:3.3 "/entrypoint.sh trae…" 3 hours ago Up 3 hours 0.0.0.0:80->80/tcp, [::]:80->80/tcp, 0.0.0.0:443->443/tcp, [::]:443->443/tcp, 0.0.0.0:8080->8080/tcp, [::]:8080->8080/tcp codex-traefik-1
40bd5aef5062 memcached:1.6-alpine "docker-entrypoint.s…" 3 hours ago Up 3 hours 0.0.0.0:11211->11211/tcp, [::]:11211->11211/tcp memcached
But we can also use the shorter alias docker ps
, which does the exact same thing.
The
ps
indocker ps
stands for “process status”. It’s a reference to the old-school heritage and philosophy of Unix. In these systems, theps
command is the traditional command for viewing all running processes. But here, instead of viewing processes, we’re viewing containers (aka services).
Show all running and non-running containers
The problem with docker ps
is that it only shows running containers. But sometimes you want to see ALL of the containers on your machine, including ones that are in a stopped state.
We can do this by passing in the --all
flag, or just -a
for short:
docker ps -a
This comes in handy when debugging crashed containers, or if you need to get an inventory of what containers you've accumulated over time.
Additional flags
Showing all Docker containers (including stopped ones) has the potential to return hundreds of containers, so you also can keep adding on flags to return only the containers that you want output.
There are a few simple flags available, including:
Additional Flags | Description |
---|---|
-n (--last ) |
Show only last X containers (ex. -n 2 shows last two) |
-l (--latest ) |
Show only the last created container |
--no-trunc |
Do not truncate the output (typically for IDs and commands) |
-q (--quiet ) |
Only list out the container IDs |
-s (--size ) |
Include the container file size |