How to display the resource usage statistics of a Docker container?

November 7, 2019 239 views
Docker

Recently I was asked to provide a list of the resource usage of all Docker containers which were running on a specific node. To get this information I had to do the following:

1 Answer

I used the following Docker command:

docker stats --all

You can change the --all with -a which would do the same.

This command would provide you to a nice live stream of very useful information like the CPU usage, the RAM usage, the NET I/O and more. The output would looke something like this:


CONTAINER ID        NAME                   CPU %               MEM USAGE / LIMIT     MEM %               NET I/O             BLOCK I/O           PIDS
b253d4071124        reverent_joliot        0.40%               1.703MiB / 3.853GiB   0.04%               688kB / 15.8MB      75MB / 0B           2
379cb50f3492        sharp_roentgen         0.00%               0B / 0B               0.00%               0B / 0B             0B / 0B             0

That way you could find out which container is using most of the resources on your server and possibly implement some resource limitations.

If you would like to check the resource usage for a specific container you could run:

docker stats CONTAINER_ID

If you would like to see only specific columns, you could use the --format argument:

docker stats --format "{{.Container}}: {{.CPUPerc}}"

This would return something like:

b253d4071124 0.40% 

For more information, I would suggest checking the official documentation here:

https://docs.docker.com/engine/reference/commandline/stats/

Hope that this helps!
Regards,
Bobby

  • Great! I tested with this tutorial and works very well!

    Watching this outputs I note that containers have this names ¿?:

    agitated_galileo
    crazy_bohr
    friendly_hermann
    quirky_diffie
    vigilant_gagarin
    condescending_cannon
    

    Why that names, where they come from?

    P.D.: -maybe- I must open this in another question?

    by Kamal Nasser
    Building CPU-intensive images and binaries is a very slow and time-consuming process that can turn your laptop into a space heater at times. In this tutorial, you'll create a Droplet to the remote Docker server and configure the `docker` command on your local machine to use it.
    • Hi @KS7000

      That’s a good question!

      Docker automatically generates a random name for each container.

      You can, however, give memorable names to your containers using the new -name flag for docker run. For example:

      docker run -d -name YOUR_CONTAINER_NAME youruser/mariadb
      

      You can change the YOURCONTAINERNAME part with the name that you would like your container to have.

      Hope that this helps!
      Regards,
      Bobby

Have another answer? Share your knowledge.