How do I check a Docker container’s CPU and memory usage?
docker stats provides a current resource-use sample for running containers. Read usage together with the configured limit and host capacity; a value from one instant is not a complete performance diagnosis. On multicore systems, container CPU percentages can exceed 100 percent when work uses more than one CPU.
Before you start
- Authorised Docker access.
- The actual container name and its workload baseline.
Instructions
1. Take a single sample
Specify the container to avoid mixing multiple applications. The non-streaming option returns after one sample instead of occupying the terminal indefinitely.
docker stats --no-stream appDisplays current CPU, memory, network, block-I/O and process statistics for the selected running container.
2. Check recorded exit information
If the application restarted or stopped, inspect the selected state fields. Avoid dumping the complete container configuration because it can include secret environment variables.
docker inspect --format 'status={{.State.Status}} exit={{.State.ExitCode}} oom={{.State.OOMKilled}}' appReads state and recorded out-of-memory information without exposing the environment block.
3. Compare container and host pressure
Review the service’s configured resource limits and time-aligned host metrics. Linux Docker memory reporting accounts for cache differently from raw cgroup totals, so compare equivalent measurements. Repeated high memory use needs an application or capacity investigation, not an automatic removal of all limits.
Check the result
- The affected container’s resource use is understood over the incident interval and any exit is correlated with logs and host pressure.
Troubleshooting
- The container is stopped and stats shows no data
- Use its exit state and recent logs; live resource statistics require a running container.
- A single sample looks normal
- Collect a small time-aligned series during the actual symptom instead of concluding that an intermittent spike never occurred.
Official references
Use the documentation for your installed version when a flag, service name or platform feature differs.
