CodeBlanks Logo Icon CodeBlanks

docker ps

Learn to list running containers with docker ps.

docker ps

docker ps lists the running containers; -a adds the stopped ones. Columns: ID, image, command, creation time, status, ports and name.

$ docker ps
CONTAINER ID   IMAGE   COMMAND                  CREATED         STATUS         PORTS    NAMES
7c2f4a9e1b3d   nginx   "/docker-entrypoint.…"   2 minutes ago   Up 2 minutes   80/tcp   web

Filtering and format

With --filter you can filter by status, name or image, and with --format choose the columns you want:

docker ps -a --filter status=exited
docker ps --filter ancestor=nginx
docker ps --format '{{.Names}}\t{{.Status}}'
docker stop $(docker ps -q)      # stop all running containers

Practice Filter the lists

Write two commands: list the running containers derived from the nginx image; then print only the names ({{.Names}}) of all containers.

Starter code

terminal
# buraya yaz

Sample solution

terminal
docker ps --filter ancestor=nginx
docker ps -a --format '{{.Names}}'

Expected output

CONTAINER ID   IMAGE   STATUS         NAMES
7c2f4a9e1b3d   nginx   Up 5 minutes   web
web
cache
jolly_tesla

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which flag lists only the container IDs?

  • -a
  • -l
  • -n
  • -q Correct answer

Explanation: -q (quiet) prints only the IDs; it is widely used in scripts.

2 Show only the stopped containers.

Question
docker ps -a --filter status=____
Answer
docker ps -a --filter status=exited

Explanation: A stopped container's status is exited.

3 Match the flags.

Term Meaning
-a All
-q Only IDs
--filter Filtering
--format Column selection

All lessons in Beginner