LinuxCommandLibrary

docker-stats

Monitor Docker container resource usage

TLDR

Display a live stream for the statistics of all running containers

$ docker stats
copy

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

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

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

Disable streaming stats and only pull the current stats
$ docker stats --no-stream
copy

SYNOPSIS

docker stats [OPTIONS] [CONTAINER...]

PARAMETERS

-a, --all
    Show all containers. Only running containers are shown by default.

--format string
    Pretty-print images using a Go template.

--no-stream
    Disable streaming stats and only show the current stats.

--no-trunc
    Do not truncate output.

--help
    Display help text.

DESCRIPTION

The docker stats command is a powerful tool used to display a live stream of resource usage statistics for Docker containers. It provides near real-time insights into CPU usage, memory consumption (including memory limits), network I/O, and block I/O. This allows users to quickly identify containers that are consuming excessive resources, troubleshoot performance bottlenecks, and optimize resource allocation within their Docker environment. The command aggregates and presents this data in a user-friendly tabular format. It's crucial for monitoring the health and performance of containerized applications and infrastructure. Using docker stats you can effectively manage your running docker containers and get an overview of performance in near real-time.

Unlike other monitoring tools, docker stats provides a CLI interface that allows for quick and easy examination. The command is generally used for quick system evaluation rather than complete system monitoring.

CAVEATS

The statistics provided by docker stats represent a snapshot in time. The reported values may fluctuate rapidly, and it's essential to observe trends over time rather than relying solely on instantaneous readings.

Also, the accuracy of the stats depends on the underlying kernel and cgroup support. Certain older kernels may not provide accurate resource accounting.

UNDERSTANDING OUTPUT

The output of docker stats includes the following columns:
CONTAINER ID: The unique identifier of the container.
NAME: The name of the container.
CPU %: The percentage of the host's CPU being used by the container.
MEM USAGE / LIMIT: The amount of memory being used by the container and the memory limit configured for the container.
MEM %: The percentage of the host's memory being used by the container.
NET I/O: The amount of data being sent and received by the container over the network.
BLOCK I/O: The amount of data being read from and written to the container's storage.
PIDS: The number of processes running inside the container.

EXAMPLES

docker stats: Displays resource usage statistics for all running containers.
docker stats my_container: Displays resource usage statistics for a specific container named 'my_container'.
docker stats --no-stream: Displays a single snapshot of resource usage statistics without continuous updates.

GO TEMPLATES

docker stats --format "table {{.Container}} {{.CPUPerc}} {{.MemUsage}}" allows customization using Go templates. This example outputs a table with the container name, CPU usage percentage, and memory usage.

HISTORY

The docker stats command has been a core feature of Docker since its early releases. It was introduced to provide a built-in mechanism for monitoring resource consumption of Docker containers directly from the command line. Over time, the command has been refined to improve accuracy and add new features. It's been crucial for developers and system administrators to monitor and debug containerized applications.

SEE ALSO

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

Copied to clipboard