Docker: List Running and Stopped Containers

By 

•

Updated on

•

9 min read

Terminal output showing running Docker containers with docker container ls

When you need to check which containers are running, see whether a container exited, or grab a container ID before another Docker command, the quickest tool is docker container ls. The older docker ps command works the same way.

This guide explains how to list Docker containers, show all containers including stopped ones, filter the output, and print only the fields you need.

Syntax

The docker container ls command uses this syntax:

txt
docker container ls [OPTIONS]

You can also use the older alias:

txt
docker ps [OPTIONS]

Docker also accepts docker container list and docker container ps. All four forms take the same options, and the examples in this guide use docker container ls.

List Running Docker Containers

To list the running containers, run the docker container ls command without any options:

Terminal
docker container ls

The output will look something like this:

output
CONTAINER ID   IMAGE      COMMAND                  CREATED          STATUS          PORTS      NAMES
e91d4f68fb49   postgres   "docker-entrypoint.s…"   2 minutes ago    Up 2 minutes    5432/tcp   pg
1403bbe0bb1f   redis      "docker-entrypoint.s…"   8 minutes ago    Up 8 minutes    6379/tcp   cache
1e1eacc45cd6   nginx      "/docker-entrypoint.…"   12 minutes ago   Up 12 minutes   80/tcp     web

Each line of the output includes the following columns:

  • Container ID - A unique alphanumeric string that identifies each container.
  • Image - The Docker image that is used to create the container.
  • Command - The command that is executed when starting the container.
  • Created - The creation time of the container.
  • Status - The status of the container.
  • Ports - The container’s exposed ports and any published mappings between host and container ports.
  • Names - The name of the container.

Docker lists the most recently created container first. If there are no running containers, only the header line is displayed. If you have not started any containers yet, see our guide to the docker run command .

List All Docker Containers

The -a, --all option tells docker container ls to print a list of all containers, including stopped ones:

Terminal
docker container ls -a
output
CONTAINER ID   IMAGE         COMMAND                  CREATED          STATUS                     PORTS      NAMES
e91d4f68fb49   postgres      "docker-entrypoint.s…"   2 minutes ago    Up 2 minutes               5432/tcp   pg
50d08f6d0e96   hello-world   "/hello"                 5 minutes ago    Exited (0) 5 minutes ago              hello
1403bbe0bb1f   redis         "docker-entrypoint.s…"   8 minutes ago    Up 8 minutes               6379/tcp   cache
1e1eacc45cd6   nginx         "/docker-entrypoint.…"   12 minutes ago   Up 12 minutes              80/tcp     web

The hello container printed its message and stopped. Its status is Exited (0), where 0 is the exit code of the main process in the container.

Use this form when docker container ls looks empty but you know containers were created earlier.

Show Full Output

By default, columns with a length exceeding a specified limit are truncated. Use the --no-trunc option to disable truncation:

Terminal
docker container ls --no-trunc

With --no-trunc, the CONTAINER ID column shows the full 64-character ID. The COMMAND column shows the complete command, such as /docker-entrypoint.sh nginx -g 'daemon off;' for the nginx container.

List Only Container IDs

To only display the containers’ IDs, pass the -q, --quiet option:

Terminal
docker container ls -q
output
e91d4f68fb49
1403bbe0bb1f
1e1eacc45cd6

This is useful in scripts or when you want to pass container IDs to other Docker commands, for example when you remove Docker containers in bulk.

List Only Container Names

To print only container names, use the --format option:

Terminal
docker container ls --format '{{.Names}}'
output
pg
cache
web

This is a clean way to build shell loops or quick status checks without extra columns. You can also pass a name to docker exec to open a shell inside the container .

Customize the Output Format

The --format option allows you to format the output using a Go template. For example, to print only the containers’ names and status, including the header, you would run:

Terminal
docker container ls --format 'table {{.Names}}\t{{.Status}}'
output
NAMES     STATUS
pg        Up 2 minutes
cache     Up 8 minutes
web       Up 12 minutes

This makes it easier to show only the fields you care about when checking container state.

The .Status field is written for people to read, so in scripts use .State instead. It prints a single word such as running or exited:

Terminal
docker container ls -a --format 'table {{.Names}}\t{{.State}}\t{{.Status}}'
output
NAMES     STATE     STATUS
pg        running   Up 2 minutes
hello     exited    Exited (0) 5 minutes ago
cache     running   Up 8 minutes
web       running   Up 12 minutes

The STATE column shows exited for the stopped hello container. The STATUS column adds the exit code and how long ago the container stopped.

Other placeholders you can use in the template include:

  • .ID - The container ID.
  • .Image - The image the container was created from.
  • .Command - The command that started the container.
  • .CreatedAt - The date and time the container was created.
  • .RunningFor - The time since the container was created, as shown in the CREATED column.
  • .Ports - The exposed and published ports.
  • .Size - The container disk size.
  • .Labels - All labels assigned to the container.
  • .Mounts - The volumes mounted in the container.
  • .Networks - The networks the container is attached to.

When you need machine-readable output for scripts, use json as the format:

Terminal
docker container ls --format json

Each container is printed as a JSON object on its own line, which works well with tools such as jq .

Show Container Sizes

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

Terminal
docker container ls -s

Each line will include a column named SIZE that shows the container size:

output
CONTAINER ID   IMAGE      COMMAND                  CREATED          STATUS          PORTS      NAMES     SIZE
e91d4f68fb49   postgres   "docker-entrypoint.s…"   2 minutes ago    Up 2 minutes    5432/tcp   pg        20.5kB (virtual 528MB)
1403bbe0bb1f   redis      "docker-entrypoint.s…"   8 minutes ago    Up 8 minutes    6379/tcp   cache     4.1kB (virtual 176MB)
1e1eacc45cd6   nginx      "/docker-entrypoint.…"   12 minutes ago   Up 12 minutes   80/tcp     web       81.9kB (virtual 196MB)

The writable size is shown first, followed by the virtual size of the image and container layers combined.

Show the Latest Containers

The -n, --last option tells the command to display the last n created containers, including all states. For example, to view the latest two created containers, you would run:

Terminal
docker container ls -n 2
output
CONTAINER ID   IMAGE         COMMAND                  CREATED         STATUS                     PORTS      NAMES
e91d4f68fb49   postgres      "docker-entrypoint.s…"   2 minutes ago   Up 2 minutes               5432/tcp   pg
50d08f6d0e96   hello-world   "/hello"                 5 minutes ago   Exited (0) 5 minutes ago              hello

The -n option counts every container, not only the running ones, so the stopped hello container is part of the result.

To list only the most recently created container, use -l, --latest, which is equivalent to -n 1:

Terminal
docker container ls -l

Filter Docker Containers

The --filter, -f option allows you to filter the output based on certain criteria.

For example, to view only the containers with status exited, you would run:

Terminal
docker container ls -f "status=exited"
output
CONTAINER ID   IMAGE         COMMAND    CREATED         STATUS                     PORTS     NAMES
50d08f6d0e96   hello-world   "/hello"   5 minutes ago   Exited (0) 5 minutes ago             hello

You do not need -a here; a status filter replaces the default view of running containers. The filter accepts created, restarting, running, removing, paused, exited, and dead.

You can also filter by container name:

Terminal
docker container ls -f "name=web"

The name filter matches part of a name, so the command above also lists a container named myapp-web-1. To match the exact name, wrap it in ^ and $:

Terminal
docker container ls -f 'name=^web$'

To show only running containers explicitly, use:

Terminal
docker container ls -f "status=running"

To list containers created from a specific image, use the ancestor filter:

Terminal
docker container ls -f "ancestor=nginx"

This matches containers whose image is nginx or an image built on top of it.

If you assign labels to your containers, you can filter on the label name or a specific key and value pair:

Terminal
docker container ls -f "label=environment=production"

For a list of all supported filters, check the Docker documentation .

List Containers in a Docker Compose Project

When your containers are managed by Docker Compose , docker compose ps limits the list to a single project. Run the command from the directory that contains the Compose file, usually compose.yaml:

Terminal
docker compose ps
output
NAME            IMAGE     COMMAND                  SERVICE   CREATED              STATUS              PORTS
myapp-cache-1   redis     "docker-entrypoint.s…"   cache     About a minute ago   Up About a minute   6379/tcp
myapp-web-1     nginx     "/docker-entrypoint.…"   web       About a minute ago   Up About a minute   0.0.0.0:8080->80/tcp, [::]:8080->80/tcp

Compose names each container after the project, the service, and a replica number, so the web service in the myapp project runs as myapp-web-1. The project name defaults to the name of the directory that contains the Compose file.

Add the -a option to include stopped containers:

Terminal
docker compose ps -a

The output includes only containers that belong to the Compose project, so it stays readable even when other containers run on the same host.

Quick Reference

For a printable quick reference, see the Docker cheatsheet .

TaskCommand
List running containersdocker container ls
List all containersdocker container ls -a
Show only container IDsdocker container ls -q
Show only container namesdocker container ls --format '{{.Names}}'
Show full, non-truncated outputdocker container ls --no-trunc
Show container sizesdocker container ls -s
Show latest containerdocker container ls -l
Show last N containersdocker container ls -n 5
Show only running containersdocker container ls -f "status=running"
Filter by statusdocker container ls -f "status=exited"
Filter by exact namedocker container ls -f 'name=^web$'
Filter by imagedocker container ls -f "ancestor=nginx"
List Compose project containersdocker compose ps
Custom output columnsdocker container ls --format 'table {{.Names}}\t{{.Status}}'

Troubleshooting

Cannot connect to the Docker daemon
The Docker daemon is not running. Start it with sudo systemctl start docker and run the command again.

permission denied while trying to connect to the docker API
Your user cannot access the Docker socket. Docker 28 and older print permission denied while trying to connect to the Docker daemon socket for the same problem. Run the command with sudo, or add your user to the docker group with sudo usermod -aG docker $USER and start a new shell session. The Docker installation guide covers this step in detail. Membership in the docker group grants root-level privileges, so only add trusted users. If you need to run the daemon without root privileges, use Docker rootless mode .

The output is empty even though containers were used before
Use docker container ls -a to include stopped containers, not only running ones.

FAQ

What is the difference between docker ps and docker container ls?
They are equivalent. docker ps is an alias, while docker container ls is the explicit management command.

Conclusion

To list Docker containers, use docker container ls or its alias docker ps. Add -a when you need stopped containers, and use --format or --filter when you want cleaner, task-specific output.

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 1000+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page