LinuxCommandLibrary

docker-stats

Monitor Docker container resource usage

TLDR

View documentation for the original command

$ tldr docker container stats
copy

SYNOPSIS

docker stats [OPTIONS] [CONTAINER...]

PARAMETERS

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

--format string
    Pretty-print stats using a Go template

--no-stream
    Disable streaming; pull only first result

--no-trunc
    Do not truncate output

-h, --help
    Print usage

DESCRIPTION

docker stats displays a continuous, real-time stream of resource usage statistics for one or more Docker containers. It provides essential metrics including CPU percentage, memory usage and limit (with percentage), network I/O, block I/O, and PIDs (process count).

By default, it monitors all currently running containers, refreshing every few seconds for a live view. This is invaluable for performance monitoring, identifying resource hogs, and debugging issues in containerized environments.

Users can target specific containers by name or ID. Output is tabular and human-readable, with columns like CONTAINER ID, NAME, CPU%, MEM USAGE/LIMIT, etc. Stats are aggregated from the container's cgroup data, offering insights into host resource sharing.

Common use cases include spotting memory leaks, high CPU spikes, or I/O bottlenecks during development, CI/CD pipelines, or production ops. Combine with docker ps to select containers dynamically.

CAVEATS

Stats are approximate; may vary with cgroups v1/v2, storage drivers, or privileged containers. Not suitable for high-precision billing.

OUTPUT COLUMNS

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

EXAMPLE USAGE

docker stats myapp   // Monitor specific container
docker stats --no-stream $(docker ps -q)   // One-shot for all running

HISTORY

Introduced in Docker 1.5.0 (2014) for basic monitoring. Enhanced in Docker 17.04+ with formatting and no-stream options; supports cgroups v2 since Docker 20.10.

SEE ALSO

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

Copied to clipboard