How to See Docker Container Resource Usage Easily
Use the
docker stats command to see real-time resource usage like CPU, memory, and network for running containers. You can also specify container names or IDs to focus on specific containers.Syntax
The basic syntax to view container resource usage is:
docker stats [OPTIONS] [CONTAINER...]
Where:
docker statsshows live resource usage statistics.[OPTIONS]can modify output, like--no-streamto get a single snapshot.[CONTAINER...]is optional and lets you specify one or more container IDs or names to monitor.
bash
docker stats [OPTIONS] [CONTAINER...]
Example
This example shows how to view resource usage for all running containers in real-time. It displays CPU %, memory usage, network I/O, and more.
bash
docker stats
Output
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
f3c1a2b4d5e6 my_container 0.07% 12.34MiB / 1GiB 1.21% 1.2kB / 0B 0B / 0B 5
Common Pitfalls
Some common mistakes when checking container resource usage:
- Running
docker statswithout specifying containers can overwhelm you if many containers run. - Not using
--no-streamwhen you want a single snapshot causes continuous output. - Confusing container IDs with image IDs; only container IDs or names work here.
bash
docker stats --no-stream my_container # Wrong: docker stats image_id # Right: docker stats container_id_or_name
Output
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
f3c1a2b4d5e6 my_container 0.05% 11.00MiB / 1GiB 1.07% 1.0kB / 0B 0B / 0B 4
Quick Reference
| Command | Description |
|---|---|
| docker stats | Show live resource usage for all running containers |
| docker stats --no-stream | Show a single snapshot of resource usage |
| docker stats container_name | Show resource usage for a specific container |
| docker stats --format "{{.Name}}: {{.CPUPerc}} CPU, {{.MemUsage}} Memory" | Custom output format |
Key Takeaways
Use
docker stats to monitor container CPU, memory, and network usage live.Add
--no-stream to get a one-time snapshot instead of continuous updates.Specify container names or IDs to focus on specific containers and avoid clutter.
Remember container IDs are different from image IDs when using
docker stats.Use the
--format option to customize the output for easier reading.