How to change resources allocated to a container at runtime?

I know that I can limit the resources allocated to a container when configured using docker with the -c and -m flags for CPU and memory.

However, is there a way to change these distributed resources to containers dynamically (after they are created) and without redeploying the same container with the changed resources?

+5
source share
3 answers

currently not - there is a desire to see how someone implements it, although: https://github.com/docker/docker/issues/6323

+1
source

At that time (Docker v1.11.1) has a docker update ( view documents ). With this, you can change the allocated resources on the fly.

 Usage: docker update [OPTIONS] CONTAINER [CONTAINER...] Update configuration of one or more containers --blkio-weight Block IO (relative weight), between 10 and 1000 --cpu-shares CPU shares (relative weight) --cpu-period Limit CPU CFS (Completely Fair Scheduler) period --cpu-quota Limit CPU CFS (Completely Fair Scheduler) quota --cpuset-cpus CPUs in which to allow execution (0-3, 0,1) --cpuset-mems MEMs in which to allow execution (0-3, 0,1) --help Print usage --kernel-memory Kernel memory limit -m, --memory Memory limit --memory-reservation Memory soft limit --memory-swap Swap limit equal to memory plus swap: '-1' to enable unlimited swap --restart Restart policy to apply when a container exits 
+14
source

This may appear for dockers 1.10 or 1.11 (Q1 2016): PR 15078 implements (December 2015) support for changing resources (including CPU) for both stopped and starting containers.

Update 2016: part of docker 1.10 and is documented in docker update ( PR 15078 ).

We decided to allow the installation of what we call resources, which now consists of cgroup thingies, hence PR # 18073 .
The only valid mutable container elements are in HostConfig and exactly in resources (see struct ).

 resources := runconfig.Resources{ BlkioWeight: *flBlkioWeight, CpusetCpus: *flCpusetCpus, <==== CpusetMems: *flCpusetMems, <==== CPUShares: *flCPUShares, <==== Memory: flMemory, MemoryReservation: memoryReservation, MemorySwap: memorySwap, KernelMemory: kernelMemory, CPUPeriod: *flCPUPeriod, CPUQuota: *flCPUQuota, } 
  • Team should be set (at the end: update ).
  • Permitted changes are passed as flags: for example. --memory=1Gb --cpushare=… (as PR does).
  • There is one flag for each attribute of the Resources structure (and no more, no less).

Please note that changes through docker set must be kept.
Ie, these changes will be permanent (updated in the JSON container).

+1
source

Source: https://habr.com/ru/post/1207899/


All Articles