docker-compose 规范表示 cpus 选项已弃用,但 docker 运行 表示使用 --cpus
docker-compose spec says cpus option is deprecated but docker run says use --cpus
阅读 docker-compose
规范 (https://github.com/compose-spec/compose-spec/blob/master/spec.md#cpus) 它说 cpus
选项已弃用,所以即使我使用它时它仍然有效,我认为这不是一个好主意.
cpus
DEPRECATED: use deploy.reservations.cpus
cpus define the number of (potentially virtual) CPUs to allocate to service containers. This is a fractional number. 0.000 means no limit.
另一方面,docker run
文档说 (https://docs.docker.com/config/containers/resource_constraints/#configure-the-default-cfs-scheduler) --cpus
选项更方便。
Specify the CPU CFS scheduler period, which is used alongside --cpu-quota. Defaults to 100000 microseconds (100 milliseconds). Most users do not change this from the default. For most use-cases, --cpus is a more convenient alternative.
所以我很困惑:我应该还是不应该在 docker-compose 中使用 cpus
?如果不这样做,我如何有效地控制服务 cpu 的使用?
我正在使用 docker 没有 swarm。
上下文
$ docker version
Client:
Version: 20.10.2
API version: 1.41
Go version: go1.13.8
Git commit: 20.10.2-0ubuntu1~20.04.2
Built: Tue Mar 30 21:24:57 2021
OS/Arch: linux/amd64
Context: default
Experimental: true
Server:
Engine:
Version: 20.10.2
API version: 1.41 (minimum version 1.12)
Go version: go1.13.8
Git commit: 20.10.2-0ubuntu1~20.04.2
Built: Mon Mar 29 19:10:09 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.3.3-0ubuntu2.3
GitCommit:
runc:
Version: spec: 1.0.2-dev
GitCommit:
docker-init:
Version: 0.19.0
GitCommit:
$ docker-compose version
docker-compose version 1.29.2, build 5becea4c
docker-py version: 5.0.0
CPython version: 3.7.10
OpenSSL version: OpenSSL 1.1.0l 10 Sep 2019
您应该按照警告建议使用 deploy.reservations.cpus,例如:
https://github.com/compose-spec/compose-spec/blob/master/deploy.md#cpus
services:
frontend:
image: awesome/webapp
deploy:
resources:
limits:
cpus: '0.50'
memory: 50M
reservations:
cpus: '0.25'
memory: 20M
所以这意味着 cpus
应该处于保留状态,处于部署状态。
阅读 docker-compose
规范 (https://github.com/compose-spec/compose-spec/blob/master/spec.md#cpus) 它说 cpus
选项已弃用,所以即使我使用它时它仍然有效,我认为这不是一个好主意.
cpus
DEPRECATED: use deploy.reservations.cpus
cpus define the number of (potentially virtual) CPUs to allocate to service containers. This is a fractional number. 0.000 means no limit.
另一方面,docker run
文档说 (https://docs.docker.com/config/containers/resource_constraints/#configure-the-default-cfs-scheduler) --cpus
选项更方便。
Specify the CPU CFS scheduler period, which is used alongside --cpu-quota. Defaults to 100000 microseconds (100 milliseconds). Most users do not change this from the default. For most use-cases, --cpus is a more convenient alternative.
所以我很困惑:我应该还是不应该在 docker-compose 中使用 cpus
?如果不这样做,我如何有效地控制服务 cpu 的使用?
我正在使用 docker 没有 swarm。
上下文
$ docker version
Client:
Version: 20.10.2
API version: 1.41
Go version: go1.13.8
Git commit: 20.10.2-0ubuntu1~20.04.2
Built: Tue Mar 30 21:24:57 2021
OS/Arch: linux/amd64
Context: default
Experimental: true
Server:
Engine:
Version: 20.10.2
API version: 1.41 (minimum version 1.12)
Go version: go1.13.8
Git commit: 20.10.2-0ubuntu1~20.04.2
Built: Mon Mar 29 19:10:09 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.3.3-0ubuntu2.3
GitCommit:
runc:
Version: spec: 1.0.2-dev
GitCommit:
docker-init:
Version: 0.19.0
GitCommit:
$ docker-compose version
docker-compose version 1.29.2, build 5becea4c
docker-py version: 5.0.0
CPython version: 3.7.10
OpenSSL version: OpenSSL 1.1.0l 10 Sep 2019
您应该按照警告建议使用 deploy.reservations.cpus,例如: https://github.com/compose-spec/compose-spec/blob/master/deploy.md#cpus
services:
frontend:
image: awesome/webapp
deploy:
resources:
limits:
cpus: '0.50'
memory: 50M
reservations:
cpus: '0.25'
memory: 20M
所以这意味着 cpus
应该处于保留状态,处于部署状态。