本文介绍了如何指定内存 &docker compose 版本 3 中的 CPU 限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法指定 CPU &版本 3 中指定的服务的内存.

I am unable to specify CPU & memory for services specified in version 3 .

在第 2 版中,它与mem_limit"& 一起工作正常.服务下的cpu_shares"参数.但是在使用版本 3 时它失败了,除非我使用群模式,否则将它们置于部署部分似乎不值得.

With version 2 it works fine with "mem_limit" & "cpu_shares" parameters under the services . But it fails while using version 3 , putting them under deploy section doesn't seem worthy unless i am using swarm mode .

有人可以帮忙吗?

version: "3"
services:
  node:
    build:
     context: .
      dockerfile: ./docker-build/Dockerfile.node
    restart: always
    environment:
      - VIRTUAL_HOST=localhost
    volumes:
      - logs:/app/out/
    expose:
      - 8083
    command: ["npm","start"]
    cap_drop:
      - NET_ADMIN
      - SYS_ADMIN

推荐答案

我知道这个话题有点陈旧,似乎过时了,但无论如何我能够使用这些选项:

I know the topic is a bit old and seems stale, but anyway I was able to use these options:

    deploy:
      resources:
        limits:
          cpus: '0.001'
          memory: 50M

当使用 3.7 版本的 docker-compose

when using 3.7 version of docker-compose

对我来说有帮助的是使用这个命令:

What helped in my case, was using this command:

docker-compose --compatibility up

--compatibility 标志代表(取自文档):

--compatibility flag stands for (taken from the documentation):

如果设置,Compose 将尝试将 v3 文件中的部署密钥转换为他们的非 Swarm 等价物

认为这很棒,我不必将我的 docker-compose 文件恢复到 v2.

Think it's great, that I don't have to revert my docker-compose file back to v2.

这篇关于如何指定内存 &docker compose 版本 3 中的 CPU 限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 05:33