containers

docker ps

Lists containers along with their status, ports, and identifiers. By default it shows only running containers unless -a is passed.

docker ps [OPTIONS]

Common flags

Flag Purpose
-a, --all Show all containers including stopped ones
-q, --quiet Only display container IDs (useful for scripting)
-f, --filter Filter output by conditions like status, name, or label
--format Format output using a Go template or table syntax
-s, --size Display total file size of each container
-n, --last Show N last created containers regardless of state

Examples

docker ps -a

List every container including exited

docker ps -q | xargs docker stop

Stop all running containers via piped IDs

docker ps --filter status=exited --filter ancestor=nginx

Filter exited nginx-derived containers

docker ps --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}'

Custom table output

Gotcha

Without -a you only see running containers, missing exited or created ones. Filter values are exact matches unless the filter documentation explicitly supports substring matching.

Related commands

← All Docker commands · Docker vs Kubernetes · Docker vs VMs