19.2.2.1 Ps Running Containers
A focused guide to Ps Running Containers, connecting core concepts with practical Docker and container operations.
Running containers are those in the active execution state: their primary process is alive, consuming CPU and memory, and responding to requests or performing work. docker ps without any flags shows only these containers, making it the default tool for a quick operational snapshot of what is currently active on a Docker host.
What "Running" Means
A container enters the running state when its primary process (PID 1 inside the container) starts successfully and has not yet exited. As long as that process is alive, the container is running. If the process exits — whether successfully or with an error — the container transitions to the exited state and disappears from docker ps output (though it remains visible with docker ps -a).
Listing Running Containers
docker ps
A typical output on a server:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a1b2c3d4e5f6 nginx:latest "/docker-entrypoint…" 3 hours ago Up 3 hours 0.0.0.0:443->443/tcp proxy
b2c3d4e5f6a7 postgres:15 "docker-entrypoint.s…" 3 hours ago Up 3 hours 5432/tcp db
c3d4e5f6a7b8 myapp:2.1.0 "./server" 2 hours ago Up 2 hours 0.0.0.0:8080->8080/tcp app
d4e5f6a7b8c9 redis:7 "docker-entrypoint.s…" 1 hour ago Up 1 hour 6379/tcp cache
Each line represents one actively running container.
Reading the STATUS Column
The STATUS field for a running container shows how long it has been up:
Up 5 seconds— just startedUp 3 hours— running for three hoursUp 4 days— long-running service
This elapsed time is measured from when the container last started, not from when it was created.
A container that was restarted (via a restart policy or manual restart) shows the time since the most recent start, not since its creation.
Health Checks in Running Containers
If the image or container was configured with a health check, the STATUS column includes health status:
Up 3 hours (healthy)
Up 1 hour (unhealthy)
Up 10 seconds (health: starting)
Health checks are custom commands defined in the Dockerfile or at run time that Docker executes periodically inside the container. The container remains in the running state even when unhealthy — health status does not automatically stop a container. It is used by orchestrators (like Docker Swarm or Kubernetes) to route traffic away from unhealthy instances.
Filtering Only Running Containers
Running is the default filter, but it can be specified explicitly:
docker ps -f "status=running"
This is equivalent to docker ps without flags, but the explicit filter is useful when constructing pipelines that need to be unambiguous.
Checking Running Containers by Image
To see which containers are running from a specific image:
docker ps -f "ancestor=nginx:latest"
For any image derived from a base:
docker ps -f "ancestor=ubuntu:22.04"
This shows containers built from ubuntu:22.04 or any image that used it as a base.
Monitoring Running Container Count
docker ps -q | wc -l
On Windows PowerShell:
(docker ps -q).Count
This returns the number of currently running containers. Useful for health dashboards or alert thresholds.
Continuous Monitoring with watch
On Linux and macOS, watch reruns a command at intervals, providing a live-updating view:
watch docker ps
This refreshes every 2 seconds by default. With a custom interval:
watch -n 5 docker ps
Real-Time Resource Usage for Running Containers
docker stats complements docker ps by showing live CPU, memory, and network metrics for running containers:
docker stats
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O
a1b2c3d4e5f6 proxy 0.12% 24MB / 512MB 4.69% 1.4MB / 890kB 0B / 0B
b2c3d4e5f6a7 db 2.31% 185MB / 2GB 9.25% 320kB / 124kB 12MB / 8MB
c3d4e5f6a7b8 app 1.45% 112MB / 1GB 11.2% 560kB / 210kB 0B / 0B
For a single container:
docker stats db
Checking Processes Inside a Running Container
docker top app
UID PID PPID C STIME TTY TIME CMD
root 12345 12300 0 10:00 ? 00:00:01 ./server
This lists the processes running inside the container from the host's perspective.
Viewing Logs of a Running Container
For a running container, logs accumulate in real time. To follow them:
docker logs -f app
To see only recent output:
docker logs --tail 50 app
Common Troubleshooting Patterns
Container not appearing in docker ps
If a container you just started does not appear, it likely exited immediately. Check:
docker ps -a -f "status=exited" -l
Inspect the last exited container's logs:
docker logs $(docker ps -a -q -f "status=exited" -l)
Container running but not responding
If the container shows Up X minutes but the application is not responding:
- Check logs:
docker logs app - Check health: look for
(unhealthy)in the STATUS column - Check port bindings:
docker port app - Exec into the container:
docker exec -it app bash