docker-compose资源限制&docker资源监控

资源限制设置

  • v2:pu_shares,cpu_quota,cpuset, mem_limit,memswap_limit,mem_swappines
    • docker-compose.yml
        version: '2'
        services:
          testservice:
            image: image
            container_name: container_name
            ports:
              - 'ports_out:ports'
            privileged: True
            volumes:
              - /:/rootfs:ro
              - /var/run:/var/run:rw
              - /sys:/sys:ro
              - /var/lib/docker:/var/lib/docker:ro
              - /cgroup:/cgroup:ro
            mem_limit: 512m
            restart: always
      
        networks:
          default:
            external:
              name: br0
      
    • start command:docker-compose up -d
  • v3:deploy
    • docker-compose.yml
        version: "3"
        services:
          test:
            image: image
            container_name: container_name
            deploy:
              resources:
                limits:
                  cpus: '0.50'
                  memory: 500M
        
        networks:
          default:
            external:
              name: br0
      
    • start command:docker-compose --compatibility up -d

监控

  • 查看配置:docker inspect container_name| grep Memor/Cpu
  • 实时监控资源消耗:docker stats container_name

你可能感兴趣的:(docker)