docker-compose限制内存, cpu资源以及固定ip写法

lihy0 2020-01-09

docker-compose v3版本写法

首先手动创建网络, 指定子网, 否则会报错

docker network create --subnet 172.88.88.0/24 devops
version: '3'

services:

 accountmgr-api:
   container_name: accountmgr-api
   image: harbor.rxtd.com:8082/rxtd/accountmgr-api:10
   ports:
     - 38080:8080
   networks:
     default:
       ipv4_address: 172.88.88.2

   deploy:
     resources:
        limits:
           cpus: '2'
           memory: 2G
        reservations:
           cpus: '0.5'
           memory: 200M
networks:
   default:
     external:
       name: devops

启动容器

docker-compose --compatibility -f gateway.yml up -d

由于做了资源限制, 并且没有使用swarm, 所以要加上--compatibility参数, 不然会报错

WARNING: Some services (web) use the 'deploy' key, which will be ignored. Compose does not support 'deploy' configuration - use docker stack deploy to deploy to a swarm.

相关推荐