0
0
Dockerdevops~15 mins

Container resource usage stats in Docker - Mini Project: Build & Apply

Choose your learning style9 modes available
Container resource usage stats
📖 Scenario: You are managing Docker containers on your local machine. You want to check how much CPU and memory each container is using to keep your system healthy.
🎯 Goal: Learn to use Docker commands to list running containers and display their CPU and memory usage statistics.
📋 What You'll Learn
Use the docker ps command to list running containers.
Use the docker stats --no-stream command to get resource usage of containers.
Filter the output to show only container IDs, names, CPU %, and memory usage.
💡 Why This Matters
🌍 Real World
Monitoring container resource usage helps keep applications running smoothly and prevents system overload.
💼 Career
DevOps engineers and system administrators regularly check container stats to maintain healthy infrastructure.
Progress0 / 4 steps
1
List running Docker containers
Run the command docker ps --format "{{.ID}} {{.Names}}" to list all running containers showing only their IDs and names.
Docker
Need a hint?

This command lists running containers with their IDs and names in a simple format.

2
Add option to show resource usage once
Run the command docker stats --no-stream --format "{{.Container}} {{.Name}} {{.CPUPerc}} {{.MemUsage}}" to show CPU and memory usage of running containers only once.
Docker
Need a hint?

The --no-stream option makes docker stats show usage once instead of continuously.

3
Filter output to show only container ID, name, CPU %, and memory usage
Use the command docker stats --no-stream --format "{{.Container}} {{.Name}} {{.CPUPerc}} {{.MemUsage}}" to display only container ID, name, CPU percentage, and memory usage.
Docker
Need a hint?

The format string controls which columns appear in the output.

4
Display the container resource usage stats
Run the command docker stats --no-stream --format "{{.Container}} {{.Name}} {{.CPUPerc}} {{.MemUsage}}" and observe the output showing container resource usage.
Docker
Need a hint?

The output will show each container's ID, name, CPU percentage, and memory usage.