我需要在主机上使用最新的Debian(9)或Ubuntu(17.0.4)来限制Docker容器中的CPU。
$ docker info
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 1
Server Version: 17.06.0-ce
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: cfb82a876ecc11b5ca0977d1733adbe58599088a
runc version: 2d41c047c83e09a6d61d464906feb2a2f3c52aa4
init version: 949e6fa
Security Options:
seccomp
Profile: default
Kernel Version: 4.9.20-std-1
Operating System: Ubuntu 17.04
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 7.753GiB
ID: 2JJV:EM37:VCY5:HVKQ:MUNV:VV5N:H247:XE5Q:VBFD:6VES:P62H:YXPJ
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
WARNING: No cpu cfs quota support
WARNING: No cpu cfs period support
我环顾四周,但我还没弄清楚如何在Debian / Ubuntu上实际启用CFS报价/期限支持。每当我尝试使用--cpus或--cpu-shares时,我都会收到错误:
NanoCPUs can not be set, as your kernel does not support CPU cfs period/quota or the cgroup is not mounted.
主机使用4.9.20内核运行最新的Ubuntu,因此应该有支持。在Debian 9上也一样。 有关如何安装cgroup的任何说明或一个很好的教程?
答案 0 :(得分:1)
在内核中启用:
General setup --->
-*- Control Group support --->
-*- CPU controller --->
-*- Group scheduling for SCHED_OTHER
[*] CPU bandwidth provisioning for FAIR_GROUP_SCHED
Caveat Emptor:在重新编译和安装发行版未提供的内核之前,请确保您知道自己在做什么。考虑UEFI安全启动,并从当前的.config
开始。