Difficulty: Beginner
How do you get a live view of CPU, memory, network and disk I/O for all running containers, and how do you read the numbers correctly?
Run docker stats. It opens a live, auto-refreshing table with one row per running container showing CPU %, memory usage against its limit, memory %, network I/O, block I/O and the number of processes (PIDS). Add --no-stream for a single snapshot, -a to include stopped containers, and --format to pick columns for scripts.
Docker does not sample processes itself. It reads the kernel's cgroup accounting for each container (CPU time, memory, I/O and PIDs) through the Engine API endpoint /containers/{id}/stats, and computes rates between two readings. That is why the first refresh can briefly show zeros, and why the figures match what the kernel enforces for limits.
| Column | What it means | Common misread |
|---|---|---|
| CPU % | Share of host CPU time used since the last sample | Can exceed 100% on multi-core hosts; 250% means about 2.5 cores busy |
| MEM USAGE / LIMIT | Memory charged to the container's cgroup against its limit | If no --memory is set, LIMIT is the host's total RAM |
| MEM % | Usage divided by limit | Near 100% with a limit set means an OOM kill is close |
| NET I/O | Bytes received and sent since container start | Cumulative, not per second |
| BLOCK I/O | Bytes read and written to block devices | Cumulative; often 0B for files served from page cache |
| PIDS | Processes and threads in the container | Steady growth suggests a thread or process leak |
On Linux, the memory figure subtracts reclaimable file cache (for example inactive_file on cgroup v2), so it is closer to what the OOM killer cares about than raw cgroup usage. It will still not match a JVM's heap number or Node's process.memoryUsage() exactly, because those measure from inside the runtime.
docker stats shows in seconds whether one container is pinned at its CPU quota or creeping toward its memory limit.docker stats --no-stream --format "{{.Name}},{{.CPUPerc}},{{.MemUsage}}" gives one CSV line per container that you can log or assert on.It has no history, no alerting and covers one host only. For production you would scrape the same cgroup metrics with cAdvisor or the node exporter into Prometheus and graph them in Grafana, or rely on the cloud provider's container insights. In Kubernetes the equivalent quick look is kubectl top pods, backed by metrics-server. Treat docker stats as the top command for containers: perfect for a live look, not a monitoring system.
# Live, refreshing view of all running containers
docker stats
# Only specific containers
docker stats api worker
# One snapshot, custom columns, good for logs or CI
docker stats --no-stream \
--format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.MemPerc}}\t{{.PIDs}}"
The api container is using more than one core and is at 80% of a 512 MiB limit, so it is the one to investigate. worker and redis show the host's RAM as their limit, meaning no memory limit was set.
docker stats, cgroups, Memory usage vs limit, CPU percentage, --no-stream, --format