How to allocate 50% CPU resource to docker container via `docker run`?

后端 未结 5 1927
感情败类
感情败类 2020-12-13 19:10

I have a 4-core CPU, I want to allocate 50% CPU resource to a docker container.
After reading the docker-run manual and config.go source code.
I still don\'t know ho

5条回答
  •  抹茶落季
    2020-12-13 19:48

    Note: PR 15078 is implementing (Dec. 2015) support for changing resources (including CPU) both for stopped and running container (possibly docker 1.10 ou 1.11)

    We decided to allow to set what we called resources, which consists of cgroup thingies for now, hence the following PR #18073.
    The only allowed mutable elements of a container are in HostConfig and precisely in Resources (see the struct).

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

    Note that making changes via docker set should persist.
    I.e., those changes would be permanent (updated in the container's JSON)


    Check also the latest (July 2019, 4 years later) openJDK 8u212 (or later) which does have official Docker support in it.

提交回复
热议问题