Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limit resources in docker-compose v3

Tags:

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?

like image 771
prometheus Avatar asked Feb 25 '17 07:02

prometheus


People also ask

How do I limit docker total resources?

To limit the maximum amount of memory usage for a container, add the --memory option to the docker run command. Alternatively, you can use the shortcut -m . Within the command, specify how much memory you want to dedicate to that specific container.

What is MEM limit in Docker compose?

The MEM USAGE/LIMIT is at 2.133MiB out of the total 1.934GiB.

What is cpu quota docker?

0 of Docker onward. The --cpu-quota option specifies the number of microseconds that a container has access to CPU resources during a period specified by --cpu-period. As the default value of --cpu-period is 100000, setting the value of --cpu-quota to 25000 limits a container to 25% of the CPU resources.

Does docker limit cpu usage?

By default, all containers running on the same host can use the host CPU resources equally and without any restrictions. However, Docker can pass -c or --cpu-shares to set the weight of the CPU used by the container. If not specified, the default value is 1024.


1 Answers

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

like image 148
andrea_crotti Avatar answered Oct 01 '22 10:10

andrea_crotti