兼容模式不支持以下部署子键

cap*_*rio 5 docker docker-compose

我必须为服务使用 500MB 的内存限制和设置为 0.6 的 CPU,我还需要在 docker-compose 文件中使用版本 3。

我尝试: $ docker-compose docker_compose.yml --compatibility up

我得到:

WARNING: The following deploy sub-keys are not supported in compatibility mode and have been ignored: resources.reservations.cpus

version: '3.3'

services:
   web:
     image: myimage:1.2.3
     volumes:
       - 'delle:/home/rh'
     deploy:
      resources:
        limits:
          memory: 500M
        reservations:
          cpus: '0.6'
     networks:
       - mynetwork
       - internal

networks:
  mynetwork:
    external: true
  internal:
volumes:
    delle:
Run Code Online (Sandbox Code Playgroud)

有人可以帮忙吗?只有群吗?

Jae*_* Y. 1

不妨使用 v2 作为docker-compose 文件

version: "2.4"

services:
   web:
     image: myimage:1.2.3
     volumes:
       - 'delle:/home/rh'
     cpu_count: 1
     cpus: 0.6
     cpu_percent: 30
     mem_limit: 500m
     networks:
       - mynetwork
       - internal

networks:
  mynetwork:
    external: true
  internal:
volumes:
    delle

Run Code Online (Sandbox Code Playgroud)

对于 v3,这解释了为什么它不支持resources.reservations.cpusandresources.limits.cpus作为内存。查看主题

Docker Compose 不适用于集群模式(它部署本地容器),因此没有编排器来考虑这些限制

正如 @Kalpesh 指出的(在我的评论下面),尝试删除资源、保留 cpu

你可以通过以下方式检查它:

# run compatibility
docker-compose --compatibility up -d

docker inspect --format '{{json .HostConfig.Memory}}' <CONTAINER_NAME> | numfmt --to=iec

docker inspect --format '{{json .HostConfig.NanoCpus}}' <CONTAINER_NAME> | numfmt --to=iec

Run Code Online (Sandbox Code Playgroud)