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
docker rm Command ReferenceReference for docker rm in CI: remove one or more containers with -f and -v to force-stop and clean up volume…
docker logs Command ReferenceReference for docker logs in CI: fetch container stdout and stderr with --tail, --since, --timestamps, and -f…
docker inspect Command ReferenceReference for docker inspect in CI: print low-level JSON for containers, images, volumes, and networks, and e…