How to Check Memory and CPU Utilization of Docker Container

Published: August 28, 2020 by Author's Photo Shane Rainville | Reading time: 3 minutes
Learn how to check a Docker container's memory and CPU utilization, as well as network traffic and disk I/O to ensure everything is running fine.

In this tutorial, you are going to learn how to use the docker command to check memory and CPU utilization of your running Docker containers.

Monitoring the health of your containers is crucial for a happy and reliable environment. It’s very important to know if your container is hittings its head against a CPU, Memory, Network, or Block limit, which could be severely degrading it.

Docker Stats

The Docker command-line tool has a stats command the gives you a live look at your containers resource utilization. We can use this tool to gauge the CPU, Memory, Networok, and disk utilization of every running container.

Run the docker stats command to display the status of your containers.

docker stats
CONTAINER ID        NAME                                                                                       CPU %               MEM USAGE / LIMIT     MEM %               NET I/O             BLOCK I/O           PIDS
e51898f31223        lucid-lemon      0.00%               8.824MiB / 1.944GiB   0.44%               0B / 0B             0B / 0B             7
bc97fe8bcd66        funky-monkey    0.01%               12.05MiB / 1.944GiB   0.61%               0B / 0B             0B / 0B             6
17714162a329        hairy-lemon   0.15%               82.09MiB / 1.944GiB   4.12%               0B / 0B             0B / 0B             28
340bec496cf7        silly-sunshine        0.50%               20.28MiB / 1.944GiB   1.02%               0B / 0B             0B / 0B             32
  • Memory is listed under the MEM USAGE / LIMIT column. This provides a snapshot of how much memory the container is utilizing and what it’s memory limit is.
  • CPU utilization is listed under the CPU % column.
  • Network traffic is represented under the NET I/O column. It displays the outgoing and incoming traffic consumption of a container.
  • Storage utilization is shown under the BLOCK I/O column. This show you the amount of reads and writes a container is peforming to disk.

No Stream

By default, the docker stats command will display a live stream of stats. If you would prefer outputting the first stats pull results, use the --no-stream flag.

docker stats --no-stream
CONTAINER ID        NAME                                                                                       CPU %               MEM USAGE / LIMIT     MEM %               NET I/O             BLOCK I/O           PIDS
e51898f31223        k8s_postgres_postgres-778965fcc7-rc2wj_default_8c8e771b-5b1a-43ee-a9ea-e4af2c1e9319_0      0.00%               8.695MiB / 1.944GiB   0.44%               0B / 0B             0B / 0B             7
bc97fe8bcd66        k8s_wordpress_wordpress-69b59478c4-5lvkk_default_1c19bdb0-2dbc-4c74-9c23-fd1f19c785bc_0    0.01%               12.05MiB / 1.944GiB   0.61%               0B / 0B             0B / 0B             6
17714162a329        k8s_mysql_wordpress-mysql-b5ddc8dd9-4xmqr_default_7694cbcb-ae3e-4bc8-a767-56c4261202f8_0   0.12%               82.09MiB / 1.944GiB   4.12%               0B / 0B             0B / 0B             28
340bec496cf7        k8s_mongodb_mongodb-5d75bdb4d7-7phxp_default_14986721-98a2-4e22-9e4a-94c569b7702e_0        0.47%               20.46MiB / 1.944GiB   1.03%               0B / 0B             0B / 0B             32

All Containers

By default, docker stats will only output results for running containers. If you would like to output stats for all containers you can use the -a or --all flags with the command.

docker stats --no-stream -a

You maybe wondering why someone would want to output stats for containers that are not running. One use case is ensuring that a container is no longer running, or displaying a list of stopped containers with the running containers and their stats.

Conclusion

The native Docker tools provide a limited glimps into the health of your containers, but its enough to understand how each one is utilizing system resources. We determine whether a container is CPU or Memory blocked, how much network traffic is hitting or being generated by a container, and how hard it’s disk storage is being hit.

Last updated on August 28, 2020 by Shane Rainville: Change title 4ca58cf4939185b3534a0d637d3f1d182c4958ef
Author Photo
Blogger, Developer, pipeline builder, cloud engineer, and DevSecOps specialist. I have been working in the cloud for over a decade and running containized workloads since 2012, with gigs at small startups to large financial enterprises.

How to Deploy Jekyll on Kubernetes

Publised September 15, 2020 by Shane Rainville

Learn how to check a Docker container's memory and CPU utilization, as well as network traffic and disk I/O to ensure everything is running fine.

How to Deploy Java Apps with Tomcat on Kubernetes

Publised September 1, 2020 by Shane Rainville

Learn how to check a Docker container's memory and CPU utilization, as well as network traffic and disk I/O to ensure everything is running fine.

How to Create a Docker Pipeline With Jenkins

Publised August 30, 2020 by Shane Rainville

Learn how to check a Docker container's memory and CPU utilization, as well as network traffic and disk I/O to ensure everything is running fine.

How to Remove Docker Containers and Volumes

Publised August 28, 2020 by Shane Rainville

Learn how to check a Docker container's memory and CPU utilization, as well as network traffic and disk I/O to ensure everything is running fine.

How to Add Persistent Data to Mysql with Docker Compose

Publised August 27, 2020 by Shane Rainville

Learn how to check a Docker container's memory and CPU utilization, as well as network traffic and disk I/O to ensure everything is running fine.

How to Set PHP Options for Wordpress in Docker

Publised August 27, 2020 by Shane Rainville

Learn how to check a Docker container's memory and CPU utilization, as well as network traffic and disk I/O to ensure everything is running fine.

How to Solve Wordpress Redirects to Localhost 8080

Publised August 27, 2020 by Shane Rainville

Learn how to check a Docker container's memory and CPU utilization, as well as network traffic and disk I/O to ensure everything is running fine.

How to Upgrade PostgreSQL in Docker and Kubernetes

Publised August 25, 2020 by Shane Rainville

Learn how to check a Docker container's memory and CPU utilization, as well as network traffic and disk I/O to ensure everything is running fine.