docker-compose 限制内存、CPU
docker-compose 使用 3.7 版本,然后加入 deploy,例如:
version: "3.7"
services:
redis:
image: mysql:alpine
container_name: mysql
deploy:
resources:
limits:
cpus: '0.50'
memory: 500M
限制 CPU 使用率 50%, 500MB 内存
需要注意的是,启动时需增加 –compatibility 选项
docker-compose --compatibility up -d
否则会报错
WARNING: Some services (mysql, rsnmp) use the ‘deploy’ key, which will be ignored. Compose does not support ‘deploy’ configuration – use docker stack deploy
to deploy to a swarm.
注:
–compatibility 是 docker-compose 1.20.0 加入,主要目的就是用来将 deploy 中的数据限制、replicas 与重启策略直接转译为 version 2 的语法