docker 和 docker compose 限制资源

原创
10/14 14:16
阅读数 28

docker 限制资源

docker run --cpus 4 -m 8G 

参考 https://docs.docker.com/engine/reference/commandline/run/

docker compose 限制资源

使用 deploy.resources.limits 来现在资源

deploy:
      resources:
        limits:
          cpus: '4' # 限制cpu 4核
          memory: 16G # 现在内存16G
version: '3'

services:
  kms-mysql:
    image: mysql:5.7
    hostname: kms-mysql
    container_name: kms-mysql
    restart: always
    volumes:
      - ./mysql/data:/var/lib/mysql
      - ./mysql/conf/my.cnf:/etc/mysql/conf.d/my.cnf
      - ./mysql/conf/mysqld.cnf:/etc/mysql/my.cnf
    environment:
      MYSQL_ROOT_PASSWORD: rootroot
      MYSQL_DATABASE: kms-service
      TZ: Asia/Shanghai
    networks:
      - kms
  kms-api:
    restart: always
    image: openjdk:8
    hostname: kms-api
    container_name: kms-api
    deploy:
      resources:
        limits:
          cpus: '4'
          memory: 16G
    volumes:
      - ./jars/kms-service.jar:/data/kms.jar
    ports:
      - "18005:18005"
    command: "java -jar /data/kms.jar --spring.profiles.active=test"
    networks:
      - kms
networks:
  kms:

查看 docker 容器资源使用情况

docker stats $CONTAINER_ID

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部