Docker Stats — Real-Time Container Resource Monitoring
What Is Docker Stats in Simple Terms?
docker stats is the quickest way to see what resources your containers are consuming right now — CPU usage, memory usage, network traffic, and disk I/O, updated every second in your terminal.
Bash
# Live stats for all running containersdocker stats # Output:# CONTAINER CPU % MEM USAGE/LIMIT MEM % NET I/O BLOCK I/O# payment-api 2.5% 128MiB/512MiB 25.0% 2MB/1MB 0B/0B# postgres 0.8% 256MiB/1GiB 25.0% 100B/50B 50MB/5MB# redis 0.1% 12MiB/512MiB 2.3% 500B/200B 1MB/0BReading the Output
◈ DIAGRAM
CONTAINER <- container name or IDCPU % <- CPU usage as % of total host CPU (200% = 2 full cores on a 4-core host)MEM USAGE <- current memory usedMEM LIMIT <- memory limit set for containerMEM % <- (MEM USAGE / MEM LIMIT) * 100 Warning: > 85% = approaching OOMKillNET I/O <- bytes received / transmitted over networkBLOCK I/O <- bytes read / written to diskPIDs <- number of processes inside containerUseful docker stats Patterns
Bash
# One-shot snapshot (no live update) — for scripts and CIdocker stats --no-stream # Stats for specific containers onlydocker stats payment-api postgres # Formatted output for scriptingdocker stats --no-stream \ --format "{{.Name}}: CPU={{.CPUPerc}} MEM={{.MemUsage}} ({{.MemPerc}})"# payment-api: CPU=2.5% MEM=128MiB / 512MiB (25.0%)# postgres: CPU=0.8% MEM=256MiB / 1GiB (25.0%) # Watch for memory pressure — alert if any container above 85%docker stats --no-stream --format \ '{{.Name}} {{.MemPerc}}' | \ awk '{gsub("%","",$2); if($2>85) print "WARNING: " $1 " at " $2 "%"}' # Continuous monitoring with timestampswatch -n 5 'docker stats --no-stream'Updating Limits on Running Containers
Bash
# If stats shows a container approaching its memory limit:docker update --memory 1g payment-apidocker update --cpus 2 payment-api# Changes cgroup limits live — no restart needed# Useful for emergency capacity increase during incidentsDocker Stats vs Prometheus
Bash
docker stats: Good for: quick checks, development, debugging Bad for: alerting, historical data, multi-host No persistence, terminal-only Prometheus + cAdvisor: Good for: production monitoring, alerting, dashboards Collects same metrics as docker stats but persistently Works across multiple hosts Use for productionPLACEMENT PRO TIP**Tip:** Memory percentage (`MEM %`) is the most important column to watch. When a container reaches 100% of its memory limit, the kernel kills it immediately (OOMKill, exit code 137). Set alerts when any container exceeds 85% — that gives you time to investigate and increase the limit before the OOMKill happens.