Containers are meant to run applications and at some point in time there is a requirement to monitor and control the resources that are getting allocated to them. While there are several GUI based tools to monitor resource utilization like cAdvisor, at times having something simple and handy can be very useful. Docker has a lightweight way to monitor containers by using
$ docker stats <container_id>
stats command above gives data about CPU usage, memory usage, network usage and I/O usage.
Along with monitoring, Docker also proides with ways to limit the usage of various resources.
- Limiting memory usage: We can use
docker runcommand to limit maximum memory utilization of any container.
- Limiting CPU usage: There are two ways managing CPU resources. We can put relative weights where a container with weight, say 1000, will get twice as much CPU as a container with weight 500. This can be done by passing
docker runcommand. Another way is to specify how long can a container use CPU in a given time period. This can be done by supplying two command line options together to
--cpu-quota=25000. These flags mean that the container will get 25ms of CPU time every 100ms, which means 25% of the CPU.
For more resource controls and ways to manage the containers, have a look at the docker run documentation.