Limit resources in docker-compose v3

后端 未结 3 1079
[愿得一人]
[愿得一人] 2020-12-29 04:29

mem_limit is no longer supported in version 3 of docker-compose.yml file. The documentation tells that I should use the deploy.resources key instead but also th

相关标签:
3条回答
  • 2020-12-29 04:36

    I was searching for this issue a while ago. I have found my answer here. At first, I tried to implement this functionality without using docker stack, but that did not work.

    Here is the piece of code which you would use to limit container's CPU/memory consumption. For additional attributes, you can search the documentation of docker.

     deploy:
      replicas: 5
      resources:
        limits: 
          cpus: "0.1"
          memory: 50M
    

    Compose file does not recognize deploy attributes, unless you deploy the application as a stack.

    0 讨论(0)
  • 2020-12-29 04:41

    I was wondering the same thing and found this: https://github.com/docker/compose/issues/4513

    So in short it's just not possible to do that, you have to use the version 2.1 of the docker-compose format to be able to specify limits that are not ignored by docker-compose up

    0 讨论(0)
  • 2020-12-29 04:47

    you can try docker-compose --compatibility up which is CLI flag that convert v3 files to their v2 equivalent, with deploy options translated when possible.

    0 讨论(0)
提交回复
热议问题