0
0
DockerHow-ToBeginner · 3 min read

How to List All Containers in Docker: Commands and Examples

Use the docker ps command to list running containers. To list all containers, including stopped ones, use docker ps -a. This shows container IDs, names, status, and more.
📐

Syntax

The basic command to list containers is docker ps. Adding -a shows all containers, not just running ones.

  • docker ps: Lists only running containers.
  • docker ps -a: Lists all containers, including stopped and exited.
  • docker ps -q: Lists only container IDs.
bash
docker ps [OPTIONS]

# Common options:
# -a : Show all containers (default shows just running)
# -q : Only display container IDs
💻

Example

This example shows how to list all containers on your system, including those that are stopped.

bash
docker ps -a
Output
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f3b1c2d4e5f6 nginx:latest "/docker-entrypoint.…" 2 hours ago Exited (0) 30 minutes ago webserver 9a8b7c6d5e4f redis:alpine "docker-entrypoint.s…" 3 hours ago Up 2 hours 6379/tcp redis_cache
⚠️

Common Pitfalls

Many users forget to add -a and only see running containers. Also, using docker ps without options shows limited info. To get container IDs only, use -q.

Wrong: docker ps (shows only running containers)

Right: docker ps -a (shows all containers)

bash
docker ps
# Only running containers shown

docker ps -a
# All containers shown
📊

Quick Reference

CommandDescription
docker psList running containers
docker ps -aList all containers (running and stopped)
docker ps -qList only container IDs
docker ps -aqList all container IDs

Key Takeaways

Use docker ps -a to list all containers, including stopped ones.
Without -a, docker ps shows only running containers.
Use -q to get only container IDs for scripting.
Remember container status is shown in the output to understand if containers are running or exited.