Skip to content
Latchkey

docker ps Command Reference

List containers.

docker ps lists running containers by default; -a includes stopped ones. In CI it is used to find service containers, collect IDs for cleanup, or verify that an expected container is up before running a smoke test against it.

Common flags

  • -a, --all - show all containers, not just running ones
  • -q, --quiet - output only container IDs
  • --filter - filter, e.g. status=exited or name='web'
  • --format - Go template output for scripting
  • -n, --last - show the n most recently created containers

Example

shell
docker ps --filter "status=running" --format "{{.Names}} {{.Status}}"
docker rm -f $(docker ps -aq --filter "name=test-")

In CI

Use docker ps -aq with a name filter to gather leftover containers for forced removal between jobs. Pair --format with a health check loop to wait until a service container reports healthy before running integration tests.

Key takeaways

  • -a includes stopped containers; default shows only running ones.
  • -aq with a filter yields IDs for batch cleanup with docker rm -f.
  • Use --format with a status filter to wait for a container to be ready.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →