Pages

Sunday, June 18, 2023

What are Cgroups in Containers?

What are Cgroups in Containers?


Cgroups help to limit the use of resources so that a single container is not utilizing all the resources available. It allows managing various system resources such as:

-CPU - limit CPU utilization.
-Memory - limit memory usage.
-Disk I/O - limit disk I/O.
-Network - limit network bandwidth.

With the help of cgroups docker engine helps to share available hardware resources with the container and puts a limit on how much resources the container can use.

Example:

docker run -it -d --name CPUTEST --cpus=0.5 centos
38a4235cc66a9d8f9bb2a4c5e1d1e7146ffeb1c63d4e2a17653f174ee725be29

$ docker run -it -d --name MEMTEST --memory=100m centos
1c7609f234d3d51ae7f29fc52a54f1202d33d4a213fd51a28bd7c46c8809145a

$ docker run -it -d --name MEM_CPU_TEST --memory=100m --cpus=0.5 --hostname server01 centos
09214e7eb0ff3ca12f81d4ae6f4de89f545910b9ce5e70037df204ce4b563543

$ docker create --privileged=true --restart=always --memory 6m --ip 172.17.0.29 -u root -v data1:/MQMAPP -w /MQMAPP -h server01.mqm.com --dns 8.8.8.8 --name MYMQM1 -it --init centos
71831091f69b0034fd03a619885088afc14e6aee614769eedb6d3b2eaace3061

-w Working directory inside the container
-v  Volume name/Bind mount a volume
-h  hostname of a container

No comments:

Post a Comment