LinuxCommandLibrary

docker-container-stats

TLDR

Display a live stream for the statistics of all running containers

$ docker [[stats|container stats]]
copy

Display a live stream of statistics for one or more containers
$ docker [[stats|container stats]] [container1 container2 ...]
copy

Change the columns format to display container's CPU usage percentage
$ docker [[stats|container stats]] --format "[.Name]:\t[.CPUPerc]"
copy

Display statistics for all containers (both running and stopped)
$ docker [[stats|container stats]] [[-a|--all]]
copy

Disable streaming stats and only pull the current stats
$ docker [[stats|container stats]] --no-stream
copy

SYNOPSIS

docker stats [OPTIONS] [CONTAINER...]
docker container stats [OPTIONS] [CONTAINER...]

PARAMETERS

-a, --all
    Show all containers (default: only running)

--format string
    Pretty-print using a Go template

--no-stream
    Disable streaming; show single snapshot

--no-trunc
    Do not truncate output

DESCRIPTION

The docker stats (or docker container stats) command displays live, real-time resource usage statistics for Docker containers. It streams metrics including CPU %, memory usage and limit, network I/O, block I/O, and PIDs, updating every second by default. This tool is essential for monitoring container performance, debugging resource bottlenecks, and ensuring efficient resource allocation in production environments.

Without arguments, it shows stats for all running containers. Specify one or more container names or IDs for targeted monitoring. The output is tabular: CONTAINER ID, NAME, CPU % (host CPU utilization), MEM USAGE / LIMIT (e.g., 10.5MiB / 2GiB), MEM %, NET I/O (e.g., 1.2kB / 1kB), BLOCK I/O (e.g., 0B / 4.1kB), and PIDs.

Use --no-stream for a single snapshot. Custom formatting via --format uses Go templates (e.g., '{{.CPUPerc}}%'). It's lightweight, non-interactive, and supports piping to tools like grep or log aggregators. Stats reflect cgroup data, accurate for Linux but approximated on other platforms.

CAVEATS

Streams indefinitely by default (Ctrl+C to stop); stats unavailable or static for stopped/paused containers even with -a; high-frequency updates may impact performance on busy systems.

DEFAULT OUTPUT COLUMNS

CONTAINER ID | NAME | CPU % | MEM USAGE/LIMIT | MEM % | NET I/O | BLOCK I/O | PIDs

EXAMPLE USAGE

docker stats myapp (single container)
docker stats --no-stream $(docker ps -q) (all running, one-shot)

HISTORY

Introduced in Docker 1.5.0 (February 2014) as part of core CLI for container monitoring; evolved with cgroup v2 support in Docker 20.10+.

SEE ALSO

docker ps(1), docker top(1), top(1), htop(1)

Copied to clipboard