0
0
Dockerdevops~10 mins

Container resource usage stats in Docker - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Container resource usage stats
Start docker stats command
Docker daemon collects stats
Retrieve CPU, Memory, Network, I/O data
Display stats in real-time
User views resource usage
Stop command to end stats
The docker stats command starts, the daemon collects container resource data, then displays it live until stopped.
Execution Sample
Docker
docker stats --no-stream
CONTAINER ID   NAME       CPU %   MEM USAGE / LIMIT   MEM %   NET I/O     BLOCK I/O   PIDS
abc123def456   my_app     2.34%   50MiB / 1GiB       4.88%   1.2MB / 0.8MB  10MB / 5MB  12
This command shows a snapshot of resource usage for running containers without continuous updates.
Process Table
StepActionData CollectedOutput Displayed
1Run 'docker stats --no-stream'Start stats collectionHeader row with column names
2Docker daemon collects CPU usageCPU % for each containerCPU % column shows e.g. 2.34%
3Docker daemon collects Memory usageMemory used and limitMEM USAGE / LIMIT and MEM % columns filled
4Docker daemon collects Network I/OBytes sent and receivedNET I/O column shows e.g. 1.2MB / 0.8MB
5Docker daemon collects Block I/ODisk read/write bytesBLOCK I/O column shows e.g. 10MB / 5MB
6Docker daemon collects PIDsNumber of processesPIDS column shows e.g. 12
7Display all collected data in tableAll stats combinedFull stats row for container displayed
8Command ends (no streaming)Stop collectingStats output ends after one snapshot
💡 Command ends after one snapshot because of --no-stream option
Status Tracker
VariableStartAfter Step 2After Step 3After Step 4After Step 5After Step 6Final
CPU %N/A2.34%2.34%2.34%2.34%2.34%2.34%
Memory UsageN/AN/A50MiB / 1GiB50MiB / 1GiB50MiB / 1GiB50MiB / 1GiB50MiB / 1GiB
Memory %N/AN/A4.88%4.88%4.88%4.88%4.88%
Network I/ON/AN/AN/A1.2MB / 0.8MB1.2MB / 0.8MB1.2MB / 0.8MB1.2MB / 0.8MB
Block I/ON/AN/AN/AN/A10MB / 5MB10MB / 5MB10MB / 5MB
PIDsN/AN/AN/AN/AN/A1212
Key Moments - 3 Insights
Why does the 'docker stats' command keep updating the output by default?
By default, 'docker stats' streams live data continuously. In the execution_table, step 8 shows the command ends only because of the '--no-stream' option.
What does the 'MEM USAGE / LIMIT' column represent?
It shows how much memory the container uses versus its maximum allowed memory. Step 3 in the execution_table shows this data is collected and displayed.
Why might CPU % be low even if the container is busy?
CPU % is a snapshot of usage at that moment. If the container is busy intermittently, the snapshot might catch it at a low usage time, as shown in step 2.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 4, what resource data is collected?
AMemory usage
BNetwork I/O
CCPU usage
DBlock I/O
💡 Hint
Check the 'Data Collected' column at step 4 in execution_table
At which step does the command stop collecting stats due to the '--no-stream' option?
AStep 6
BStep 7
CStep 8
DStep 5
💡 Hint
Look at the 'exit_note' and step 8 in execution_table
According to variable_tracker, what is the value of 'PIDs' after step 6?
AN/A
B12
C0
DUnknown
💡 Hint
Check the 'PIDs' row in variable_tracker under 'After Step 6'
Concept Snapshot
docker stats command shows live resource usage of containers
By default, it streams continuously; '--no-stream' shows one snapshot
Displays CPU %, memory usage and limit, network I/O, block I/O, and PIDs
Useful for monitoring container health and performance
Stops when user interrupts or with '--no-stream' option
Full Transcript
The docker stats command starts by sending a request to the Docker daemon to collect resource usage data for running containers. The daemon gathers CPU usage, memory usage and limits, network input/output, block device input/output, and the number of processes (PIDs) for each container. This data is displayed in a table format with columns for each metric. By default, docker stats streams this data live, updating continuously until the user stops it. Using the '--no-stream' option makes the command show only one snapshot and then exit. This helps users monitor container resource consumption in real time or as a single report.