docker ps -a: list containers, filter, and clean output format
List running and stopped containers with docker ps -a, get a clean table with --format, filter by status, and use the commands you reach for next.
docker ps lists running containers only. Add -a to include stopped ones. The default output is wide and wraps badly in a small terminal, but --format lets you choose the columns.
Find a container and see what it is doing
- List running containers: docker ps.
- Include stopped ones with docker ps -a.
- Read a container's output: docker logs -f containername.
- Open a shell inside it: docker exec -it containername sh.
Commands you can copy
docker psdocker ps -adocker ps -aqdocker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"docker ps -a --filter status=exiteddocker ps -sdocker ps -ldocker logs -f containernamedocker exec -it containername shdocker stop containernamedocker compose down -vOptions explained
- -a, --all
- Shows all containers. The default list shows only running ones.
- --format
- Formats output with a template: table, table TEMPLATE, json or a Go template. Columns such as {{.Names}}, {{.Status}} and {{.Ports}} are the useful ones.
- -q, --quiet
- Prints only container IDs. Combine with -a to pass IDs to another command.
- -f, --filter
- Filters as key=value. The status filter accepts created, restarting, running, removing, paused, exited and dead. Repeat -f for several filters.
- -s, --size
- Shows disk size. Size is the writable layer; virtual size includes the read-only image.
- -l and -n
- -l shows the most recently created container in any state, -n N the last N.
- A port conflict
- If docker says a port is already allocated, see port is already allocated and how port mapping works.
- Container exits at once
- Check docker logs containername for the reason. Our Docker Compose generators list the usual startup errors for each service.
- docker compose down -v
- The -v also deletes the named volumes, which is where a database keeps its data. Leave it out if you want to keep the data.
Questions about Docker ps and common commands
- How do I list all running Docker containers?
- docker ps. Add -a to include stopped containers.
- How do I get cleaner docker ps output?
- Use --format with a table template, for example --format "table {{.Names}}\t{{.Status}}".
- How do I see only stopped containers?
- docker ps -a --filter status=exited.
- How do I see what a container is logging?
- docker logs -f containername.