What does `docker stats` actually show?
Running `docker stats` with no arguments prints a live-updating table for every running container. Each row shows:
- •CPU % -- percentage of one CPU core, so a container on a 4-core host can show up to 400%
- •MEM USAGE / LIMIT -- current resident memory against the container's memory limit (or host total if no limit is set)
- •MEM % -- memory usage as a percentage of that limit
- •NET I/O -- cumulative bytes received and sent on the container's network interface since it started
- •BLOCK I/O -- cumulative bytes read and written to block devices
- •PIDS -- number of processes (threads) inside the container
The numbers refresh roughly once per second, the same cadence the Docker daemon reads from Linux cgroups. They are point-in-time samples, not averages, so a brief spike can dominate the view.
How do you sort `docker stats` output by memory or CPU?
`docker stats` has no built-in sort flag. The standard pattern is to take a single snapshot with `--no-stream`, format the output with `--format`, then pipe to `sort`.
Sort by memory usage (column 4 in the default numeric sort):
# Sort by memory percentage, highest first
docker stats --no-stream --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.MemPerc}}" \
| (read header; echo "$header"; sort -t$'\t' -k4 -rh)
# Sort by CPU percentage, highest first
docker stats --no-stream --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.MemPerc}}" \
| (read header; echo "$header"; sort -t$'\t' -k2 -rh)The `read header` trick preserves the header row while sorting only the data rows. The `-h` flag tells `sort` to handle human-readable suffixes like MiB and GiB correctly. Adjust `-k` to the column number you want to sort on.
Available format fields you can use with `--format`:
- •{{.Name}} -- container name
- •{{.ID}} -- short container ID
- •{{.CPUPerc}} -- CPU percentage string (e.g. 2.34%)
- •{{.MemUsage}} -- memory used / limit (e.g. 512MiB / 2GiB)
- •{{.MemPerc}} -- memory percentage string
- •{{.NetIO}} -- network I/O
- •{{.BlockIO}} -- block I/O
- •{{.PIDs}} -- process count
What does `--no-stream` do, and when should you use it?
`docker stats --no-stream` collects one sample from each container and exits immediately, rather than refreshing continuously. Use it when:
- •You are writing a shell script or cron job that checks container resource use and needs a clean exit
- •You want to sort output, since a live stream cannot be piped to sort meaningfully
- •You are logging a point-in-time snapshot to a file
- •A terminal that does not support the ANSI escape sequences used by the live view is involved
One limitation: a single sample can miss a short burst. If you want to catch intermittent spikes, run `--no-stream` on a schedule (for example, every 30 seconds from cron) and append results to a log file.
How do you use `docker stats` with Docker Compose?
Docker Compose has no separate stats subcommand. The standard approach is to pass container names or IDs directly to `docker stats`. Compose names containers predictably as `<project>-<service>-<index>`, so you can filter by project prefix:
# Show stats only for containers in the "myapp" Compose project
docker stats $(docker compose -p myapp ps -q)
# Or name them explicitly
docker stats myapp-web-1 myapp-worker-1 myapp-db-1If your Compose file is in the current directory, `docker compose ps -q` returns the IDs of all services in that project, which you can pass straight to `docker stats`.
What are the limits of `docker stats`, and when do you need something more?
`docker stats` is a quick diagnostic tool, not a monitoring system. Its practical limits:
- •No history -- the moment you close the terminal, the data is gone
- •No alerting -- there is nothing to wake you up when a container hits 90% memory at 3 am
- •No trends -- you cannot see whether memory has been growing for the past six hours
- •No process-level detail inside the container -- for that you need `docker exec <id> top` or `docker exec <id> ps aux`
- •CPU % is relative to one core, which makes multi-core containers harder to read
- •Memory figures exclude the kernel page cache on older Docker versions, so actual pressure can be higher than shown
For teams running containers in production without a dedicated SRE, Opservo auto-discovers all running Docker containers and tracks their CPU, memory and status continuously. When a container stops or crash-loops, an alert goes out immediately. The agent is a single static Go binary under 15 MB; it opens no inbound ports and reads container data the same way `docker stats` does, via the Docker daemon socket.
How Opservo installs:
curl -sSL https://api.getopservo.com/install.sh | sudo bashIt takes about 30 seconds, requires no configuration, and shows the first findings within five minutes. The free plan covers two servers at no cost and no card required.
Last updated 2026-11-21.