Docker Community Forums

Share and learn in the Docker community.

Confusing Load Balancing Behavior in Docker for AWS swarm

I am confused with the Swarm load balancing behavior - because I don’t see pages generated by all of the replicas in my service. I see pages generated by one replica in my swarm service - most of the time. I do see others, but the load balancer doesn’t seem to round robin the requests to all of the service replicas - it seems to stick with a give replica for some time and then switch for no apparent reason.

Expected behavior

I would expect that each time I refresh my browser, I would receive a page rendered from a different container. My node.js app in the replicated container renders a page that shows a unique ID for the running node.js process. This helps me know which container (node.js process) rendered the page.

Actual behavior

I get the same page, with the same unique node.js process id most of the time. After many page refreshes I might get a new node.js process id. But then that continues to be the same over the next many page refreshes. I observe the same behavior from the Postman app (another app that can send HTTP requests). So I don’t think it’s the browser caching the page. Additionally, I am using hard page refresh commands each time I refresh the page, which should ignore anything cached anyway.

Additional Information

Using the Docker Cloud website I created a Docker CE Swarm in my AWS account. I can easily connect to it, and create services. I just can’t see the load balancing rotate between replicated containers of my service. I am sending my HTTP requests to the external host name for the elastic load balancer that was created as part of the swarm.

Steps to reproduce the behavior

  1. Create a new swarm in AWS (I believe it created it using the Docker CE version - because I don’t have a license for enterprise). I created a swarm with one manager and 2 workers, all using AWS t2.medium instances.

  2. Connect over SSH to your manager node

  3. Then create the service. This is the command I used…
    “docker service create --name nodejs --mode replicated --replicas 3 -p 80:80 juddflamm/node-web-sample”

  4. Then hit the URL from your browser. The URL is the single elastic load balancer’s external URL (port 80).

  5. Then do hard refreshes in that browser window, noticing that instead of getting a page with a different node.js process id, you get the same process id; almost all of the time - but not always.