0
0
DockerHow-ToBeginner · 3 min read

How to List Running Containers in Docker

Use the docker ps command to list all running containers in Docker. This command shows container IDs, names, status, and other details of containers currently active.
📐

Syntax

The basic command to list running containers is docker ps. You can add options to customize the output:

  • docker ps: Lists all running containers.
  • docker ps -a: Lists all containers, including stopped ones.
  • docker ps --format: Customize output format.
bash
docker ps
💻

Example

This example shows how to list running containers with docker ps. It displays container ID, image, command, creation time, status, ports, and names.

bash
docker ps
Output
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f3c1a2b4d5e6 nginx:latest "/docker-entrypoint.sh" 2 hours ago Up 2 hours 0.0.0.0:80->80/tcp webserver 7a8b9c0d1e2f redis:alpine "docker-entrypoint.sh" 3 hours ago Up 3 hours 6379/tcp redisdb
⚠️

Common Pitfalls

Some common mistakes when listing containers:

  • Using docker ps without -a shows only running containers, so stopped containers are not listed.
  • Expecting container names instead of IDs; docker ps shows both but IDs are shorter.
  • Not having Docker running or proper permissions can cause errors.
bash
docker ps -a
# Lists all containers, including stopped ones

docker ps
# Lists only running containers
📊

Quick Reference

CommandDescription
docker psList running containers
docker ps -aList all containers (running and stopped)
docker ps --format '{{.ID}}: {{.Names}}'Custom output showing container ID and name

Key Takeaways

Use docker ps to list only running containers.
Add -a to list all containers, including stopped ones.
Check Docker service is running and you have permissions before running commands.
Container IDs are shortened but unique identifiers shown by docker ps.
Customize output with --format for easier reading or scripting.