Multiple instances of a service on a single host?

Is it not possible to have multiple instances of a service on a single host by using “scale”? I tried to use the “scale” functionality on a single host and I see only one container spin up due to port conflict. So to have 10 instances on the same node, I need to start 10 different services.
Although, docker-compose enables scaling an application on a single host without any port conflicts. Am I missing some configuration here or is it not possible?

I also tried using my own docker-compose file without any explicit port mapping and then used a rancher-compose.yml to scale it up but the issue still persists.

If there is a port conflict you won’t be able to expose the ports publicly and instead connect to them via linked services. As long as there are no ports defined within Rancher you will be able to scale as many instances of a service per node as required.

I use the load balancer + web services in this fashion and I’m currently running 5 instances of the web service on one host for my staging environments without any problems.

Hi,

Thanks for your response!
So as of now, I am only only mentioning the private port (the exposed port of the container.)
My tomcat instance is running on 8080 within the container so I add “8080” in the ‘private port’ and leave the public port blank so that it’s allocated dynamically. I also scale it to a certain number before I spin off the service. But after the first container, it returns a port conflict error.

In my docker-compose.yml file, I mention ports in the following manner:
** ports:**
** :“8080”**

When I spin it up using docker-compose and scale it to a certain number, there is no port conflict. When I do it on Rancher, it returns a port conflict error.

Maybe I am missing some step.
Thank you. :slightly_smiling:

This is a bug/missing feature. For dynamic ports on a service pick the same port for each container on each host, because 5 containers on 5 hosts with 5 different ports for a service isn’t very useful. So the scheduler finds a random port that is available on all the hosts, and then uses that. But this doesn’t have a way to handle when num_containers > num_hosts yet.

Thank you Vincent.
I am hoping this feature can be added in the near feature because it will be great if multiple containers can be spun up dynamically in the same host and across a cluster simultaneously depending on the resources or some scheduling rule.

You can do mostly this today by not mapping public ports at all (and then using a load balancer with scale <= num_hosts to access them if there are actually public ports needed).

Right. So that would effectively spin up an instance on each host and that works for me. But I was facing an issue when I was trying to scale >= number-of-hosts. Eg: when my scale value was 5 and I just had a single host.

Right… so I’m saying don’t map any public ports on the service and then you can have as many as you want running per host.

Then to actually reach those containers, you setup a balancer (with scale <= num_hosts) listening on some host port and it sends traffic to all the tomcat containers:8080. The balancer talks to the containers over the overlay network, the tomcat containers don’t need to publish ports individually.

Oh right. I will try that out. Thank you so much! :slight_smile:

Hi Vincent,

I tried the method you suggested and it worked perfectly.

Thank you for your help!