In my docker-compose
I have multiple client and worker classes, specifically a client of type A, one of type B and another of type C, with their respective worker classes. Every time I execute docker-compose
I need to use the option --scale
a total of 6 times if I want to use a number of containers different to 1 for each class: --scale cliA=2 --scale cliB=3 [...]
. Is there an alternative to having classes on my docker-compose.yml
and instead have an unified class for a client which could be scaled differently for each different class (and the same for the worker)?
I have reasoned about it, and I have come to the conclusion that it may be possible to do something like this (check the code at the end of the question for reference on the cli
class):
cli:
image: client
// More stuff
scale: 4
environment:
CLASSID=A
scale: 2
environment:
CLASSID=B
// [...]
This docker-compose.yml
would be able to create classes as needed without the need of calling --scale
every time. However, I have checked the reference for docker-compose
but I haven't found anything that helps me. I found an insightful post which mentioned that I could use docker-swarm
in order to accomplish this task, but I think it's out of the scope of the subject (this question is trying to answer an exercise).
Here is the code for the docker-compose.yml
file:
version: '2'
services:
cliA:
image: client
build: ./client/
links:
- bro
environment:
- BROKER_URL=tcp://bro:9998
- CLASSID=A
// Similar description for cliB, cliC; only CLASSID changes
worA:
image: worker
build: ./worker/
links:
- bro
environment:
- BROKER_URL=tcp://bro:9999
- CLASSID=A
// Similar description for worB, worC; only CLASSID changes
bro:
image: broker
build: ./broker/
expose:
- "9998"
- "9999"
Any help is appreciated.