Limit resources in docker-compose v3

眉间皱痕 提交于 2019-12-18 11:45:59

问题


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 that this part will only be effective with swarm or docker stack.

cpu_shares, cpu_quota, cpuset, mem_limit, memswap_limit: These have been replaced by the resources key under deploy. Note that deploy configuration only takes effect when using docker stack deploy, and is ignored by docker-compose.

... as written in the docs.

How do I set memory/cpu limits with docker-compose with v3 format of the yml file?


回答1:


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




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/42453473/limit-resources-in-docker-compose-v3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!