docker-compose限制內存, cpu資源以及固定ip寫法


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.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM