How can I scale a service but apply a different cpuset
on each instance with docker-compose ?
For example: I have 4 cpus, I want 4 instances, each using 1 unique cpu.
How can I scale a service but apply a different cpuset
on each instance with docker-compose ?
For example: I have 4 cpus, I want 4 instances, each using 1 unique cpu.
Copyright © 2021 Jogjafile Inc.
What version of docker-compose are you using? I'm asking because accomplish what you desire is only possible with docker-compose v2.x or docker-swarm as you can see below.
you can check more info here in the docker doc.
supposing that you are using docker-compose 2.4, you can define a service like this in your `docker-compose.yaml
Where
cpu_count
is number o cpu cores you want to use in the service, andmem_limit
is the limit of memory that your service can consume.To define the number of replicas you must run:
docker-compose up --scale redis=2
Where
redis
is name of the service in the docker-compose and2
is the number of replicas that you desire. So both the two containers will spin up with 1 core of CPU and 200m of memory.To check the container resources consumption you can run
docker stats
Source: https://docs.docker.com/engine/reference/run/#runtime-constraints-on-resources
https://docs.docker.com/compose/compose-file/compose-file-v2/#cpu-and-other-resources