devlent
devlent

Reputation: 152

Docker service create `n` replicas in `n-1` swarm nodes

I have 4 nodes in a Docker swarm. I create a service with official docker nginx image with 5 replicas. If I use a port mapping 80:80, only 4 containers are accessible publicly; the other one is inaccessible.

docker service create --name web -p 80:80 --replicas 5 nginx

Is there a way, I can make all the 5 nginx-running-containers publicly accessible? (two of the containers are in the same node and only one can bind to node's port 80)

Upvotes: 2

Views: 665

Answers (2)

Elton Stoneman
Elton Stoneman

Reputation: 19144

If you create n replicas of a service, they do all participate in load-balancing for the service. If one node has several instances of the service running, when the host gets a request on port 80, Docker will distribute traffic among the containers on that host.

With your 5 replicas on 4 nodes, if you throw some test traffic and check the responses, you should see that all five containers are responding. But it's difficult to check that with the default nginx image. The answer to this question uses an alternative image as a simple to verify all the containers are responding to traffic.

Upvotes: 4

Sanket Sarang
Sanket Sarang

Reputation: 127

To the best of my knowledge that is not possible unless at-least one of the servers has multiple public LAN cards / virtual networks attached. Not sure though why you would want more than one nginx instance running per node.

Upvotes: 0

Related Questions