Get a single snapshot of container stats without streaming
By default, docker stats
provides a live stream of resource usage. However, sometimes you might only need a single snapshot of the current stats without the continuous updates. In this step, you will learn how to achieve this using the --no-stream
flag.
The --no-stream
flag tells docker stats
to collect the statistics once and then exit, rather than continuously updating the output.
Let's get a single snapshot of the stats for all running containers:
docker stats --no-stream
You will see the table of container stats appear once, and then the command will exit. This is useful for scripting or when you just need a quick look at the current resource usage.
You can combine --no-stream
with other flags, such as -a
to see a snapshot of all containers (running and stopped):
docker stats -a --no-stream
This will display a single snapshot of all containers.
You can also combine it with specifying specific containers:
docker stats container1 container2 --no-stream
This will give you a single snapshot of the stats for container1
and container2
.
Using --no-stream
is efficient when you don't need the real-time updates and just want to capture the current state of resource usage.