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:
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”:
Output
Alternatively, the container’s “name” can also be specified in place of its “id”:
Output
Example 3: Monitoring the Resource Usage/Utilization of Multiple Containers
The resource utilization of multiple target containers can also be visualized, demonstrated below:
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.