I'm trying to run a system with a controller and multiple workers. While doing a udp-Healthcheck the controller acts as a UDP client and the worker act as a server. The ports where the controller/client should send the udp request to, is passed through args, using Dockers ENTRYPOINT.
The worker also gets his port that he listens to through args, using ENTRYPOINT as well.
I now want to scale the number of workers dynamically using
Docker-compose up --scale worker=[numberOfWorkers]
but I couldn't find anything on how to pass the ports that are now dynamically created from a range of ports. Here is my Docker-compose.yml:
version: '3'
services:
controller:
build: controller
container_name: controller1
volumes:
- network-log-volume:/var/controller_logs
entrypoint: [/controller, worker:80]
worker:
build: worker
ports:
- "1001-1005:80"
entrypoint: [/worker, "80", ""]
The previous "hardcoded" version (which was perfectly working) looked like this:
version: '3'
services:
controller:
build: controller
container_name: controller1
volumes:
- network-log-volume:/var/controller_logs
entrypoint: [/controller, worker1:1231, worker2:1232, worker3:1233, worker4:1234, worker5:1235, worker6:1236]
worker1:
build: worker
container_name: worker1
expose:
- "1231"
ports:
- "1231:1231"
entrypoint: [/worker, "1231", ""]
worker2:
build: worker
container_name: worker2
expose:
- "1232"
ports:
- "1232:1232"
entrypoint: [/worker, "1232", ""]
worker3:
build: worker
container_name: worker3
expose:
- "1233"
ports:
- "1233:1233"
entrypoint: [/worker, "1233", ""]
worker4:
build: worker
container_name: worker4
expose:
- "1234"
ports:
- "1234:1234"
entrypoint: [/worker, "1234", ""]
worker5:
build: worker
container_name: worker5
expose:
- "1235"
ports:
- "1235:1235"
entrypoint: [/worker, "1235", ""]
So I basically want to make the above Docker-compose.yml be scalable dynamically rather that doing it like that. Thanks!
Edit: Due to the way my lecture is structured I can not change a lot about how the controller and the worker work in general. It is supposed to work with only the docker-compose.yml
I read a bit about using swarms, but I also read that they are deprecated and not to be used anymore.