1

I'm trying to scale my game servers (nodejs) where instances should have unique ports assigned to them and where instances are separate (no load balancing of any kind) and are aware what port is assigned to them (ideally by env variable?). I've tried using docker swarm but it has no option to specify port range and I couldn't find any way to allocate or to pass the allocated port to the instance so it's aware of the port its running on e.g via env variable.

Ideal solution would look like:

Instance 1: hostIP:1000
Instance 2: hostIP:1001
Instance 3: hostIP:1002
... etc

Now, I've managed to make this work by using regular Docker (non-swarm) by binding to host network and passing env variable PORT, but this way I'd have to manually spin up as many game servers as I'd need.

My node app uses "process.env.PORT" to bind to host's IP address:port

Any opinion on what solutions I could use to scale my app?

J0k3r
  • 11
  • 2

2 Answers2

0

You could try different approaches.

  • Use docker compose and external service for extracting data from docker.sock as suggested here How to get docker mapped ports from node.js application?
  • Use redis or any key-value storage service to store port information and get it with every new instance launch. The most simple solution is to use redis incr command to get next free number but it has some limitations
Evgenii Malikov
  • 427
  • 4
  • 12
  • but as i said in the question above, the answer you provided wouldnt work for docker swarm because it cant assign random ports or can it? – J0k3r Feb 17 '20 at 19:58
  • I don't use swarm, but it probably should work with swarm as well. You shouldn't assign ports by yourself in this case, docker will do it for you if you. Actually all your "worker" containers will use the same inner port mapped to random outer port. – Evgenii Malikov Feb 18 '20 at 10:37
-1

Not To Sure What You Mean There? Could You Provide More Detail?

Josh
  • 1
  • 3
  • all details are there, if you dont know what i mean then why post " Not To Sure What You Mean There" ? its obvious you have no clue – J0k3r Feb 17 '20 at 05:53