Runtime Limits for CPU and Memory with Docker Containers

How can we change the memory limit and limit for docker containers at runtime? I mean, while the container is running, I would like to change the memory limit like

Thank you in advance

+3


source to share


1 answer


You cannot change this inside the running container, you will need to do it on your host.

How you do this on the host depends on your host-os, on Linux I suggest taking a look at cgroups , i.e. how docker internally limits containers.

On ubuntu you can use cgm manager cgm (tried it on ubuntu 15.04).

  • create a new cgroup for the cpu, move the process (like 28433) to it and set the value
> # cgm create cpu dudecpu 
> # cgm movepid cpu dudecpu 28433 
> # cgm setvalue cpu dudecpu cpu.shares 512

      



  1. create a new group for memory, move the process (e.g. 28433) to it and set the value
> cgm create memory dudemem
> cgm movepid memory dudemem 28433
> cgm setvalue memory dudemem memory.limit_in_bytes 1000000000

      

  1. check where your new groups are and look at these directories, you will find all the properties of this group.
> find /sys/fs/cgroup/ -name "dude*"
> /sys/fs/cgroup/memory/user.slice/user-1000.slice/session-c3.scope/dudemem
> /sys/fs/cgroup/cpu,cpuacct/user.slice/user-1000.slice/session-c3.scope/dudecpu

      

+4


source







All Articles