How to List Docker Containers

By 

Updated on

6 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]

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
c8bded53da86    postgres     "docker-entrypoint.s…"   2 hours ago    Up 2 hours    5432/tcp    pg
571c3a115fcf    redis        "docker-entrypoint.s…"   4 hours ago    Up 4 hours    6379/tcp    cache
05ef6d8680ba    nginx        "nginx -g 'daemon of…"   2 hours ago    Up 2 hours    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 published ports.
  • Names – The name of the container.

If there are no running containers, only the header line is displayed.

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
b28cbaa91f15    couchbase    "/entrypoint.sh couc…"   5 hours ago    Exited (0) 3 hours ago                db
c8bded53da86    postgres     "docker-entrypoint.s…"   2 hours ago    Up 2 hours                5432/tcp    pg
571c3a115fcf    redis        "docker-entrypoint.s…"   4 hours ago    Up 4 hours                6379/tcp    cache
05ef6d8680ba    nginx        "nginx -g 'daemon of…"   2 hours ago    Up 2 hours                80/tcp      web

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

List Only Container IDs

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

Terminal
docker container ls -q
output
c8bded53da86
571c3a115fcf
05ef6d8680ba

This is useful in scripts or when you want to pass container IDs to other Docker commands.

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.

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 hours
cache    Up 4 hours
web      Up 2 hours

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

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
c8bded53da86    postgres     "docker-entrypoint.s…"   2 hours ago    Up 2 hours    5432/tcp    pg       63B (virtual 394MB)
571c3a115fcf    redis        "docker-entrypoint.s…"   4 hours ago    Up 4 hours    6379/tcp    cache    0B (virtual 98.2MB)
05ef6d8680ba    nginx        "nginx -g 'daemon of…"   2 hours ago    Up 2 hours    80/tcp      web      2B (virtual 126MB)

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
b28cbaa91f15    couchbase    "/entrypoint.sh couc…"   5 hours ago    Exited (0) 3 hours ago                db
c8bded53da86    postgres     "docker-entrypoint.s…"   2 hours ago    Up 2 hours                5432/tcp    pg

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
b28cbaa91f15    couchbase    "/entrypoint.sh couc…"   5 hours ago    Exited (0) 3 hours ago                db

You can also filter by container name:

Terminal
docker container ls -f "name=web"

To show only running containers explicitly, use:

Terminal
docker container ls -f "status=running"

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

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"
Custom output columnsdocker container ls --format 'table {{.Names}}\t{{.Status}}'

Troubleshooting

Cannot connect to the Docker daemon
The Docker daemon is not running or the current user cannot access it. Start Docker and verify your user has permission to use the Docker socket.

permission denied while trying to connect to the Docker daemon socket
Run the command with sudo or add your user to the docker group, then start a new shell session.

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 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page