Docker

How to Monitor Docker Container Resource Usage

Monitoring/Managing the resources especially containers is crucial in Docker to streamline the application deployment procedure. This approach is effective to analyze the running, exited containers and garbage the unused containers accordingly to free up memory.

This write-up will discuss:

What is Resource Usage in Docker?

The “Resource Usage” corresponds to the functionalities consuming the resources on the development machines. It basically refers to the containers consuming memory, CPU, etc.

How to Monitor Docker Container Resource Usage?

The resource usage of a Docker container can be monitored via the “Terminal” or “Docker Desktop”. Both of these methodologies will be explained in detail.

Approach 1: Monitor the Resource Usage of Containers Via Terminal

The resource usage of containers in the terminal can be analyzed via the “stats” cmdlet. This command can be used in different cases as per the requirements.

Example 1: Monitoring the Resource Usage of All the Running Containers

For monitoring resource utilization of all running containers, utilize the “docker stats” or “docker container stats” cmdlets, respectively, as follows:

docker stats

 

docker container stats

 

Output


Example 2: Monitoring the Resource Usage of a Target Container

However, to monitor/analyze the resource utilization of the desired container(s), use the “stats” cmdlet with the target container’s “id”:

docker stats 0516c91f5dda

 

Output


Alternatively, the container’s “name” can also be specified in place of its “id”:

docker stats xyz

 

Output


Example 3: Monitoring the Resource Usage/Utilization of Multiple Containers

The resource utilization of multiple target containers can also be visualized, demonstrated below:

docker container stats welcome-to-docker xyz

 

Output

Approach 2: Checking the Resource Usage From Docker Desktop

If Docker Desktop is the desired tool, the resources of the running containers can also be analyzed via this tool using an extension. To apply this methodology, consider the below-provided steps:

Step 1: Install the “Resource Usage” Extension

Open the “Docker Desktop”, click the “EXT” option from the left side bar, type “Resource usage” in the search field, and then trigger “Install” to install the extension:


Step 2: Switch to the “Resource usage” Tab

After the extension is installed, the “Resource usage” tab will be evident on the sidebar. Open it to visualize a real-time listing of each container:


Also, a “Chart view” of the containers can be seen by opening the corresponding tab. Moreover, the refresh rate for the extension (1 second – 5 minutes) can also be modified as per the requirements:

Conclusion

The “Container Resource Usage” basically refers to the containers consuming memory, or CPU and can be monitored via the “Terminal” or “Docker Desktop”. The former approach is more effective as the utilization of resources can be analyzed in a custom manner in accordance with the change in requirements from time to time. This blog elaborates on monitoring Docker container resource usage.

About the author

Umar Hassan

I am a Front-End Web Developer. Being a technical author, I try to learn new things and adapt with them every day. I am passionate to write about evolving software tools and technologies and make it understandable for the end-user.