Score:0

Docker swarm with TOMCAT and NGINX as load balancer

us flag

I am trying to set up a docker swarm where NGINX is used for the load balance of the swarm nodes.

docker swarm init --advertise-addr 192.168.99.153

Also, I add the two nodes as a swarm

docker swarm join --token SWMTKN-99-31eka5srtjyvajsbiusixh6gil8p6xuk6yejfts4co8voxu8op-a8awcomh58de8d0ofkckqnsud 192.168.99.153:2377

Now I create a service on the manager node using

docker service create --name backend --replicas 2  --publish 8080:80 tomcat

I tested the tomcat on node1/node2 browser by 192.168.99.153:8080 / 192.168.99.154:8080 and I can see tomcat landing page.

Now I set up a separate swarm on 3rd node for Loadbalancer NGINX.

docker swarm init --advertise-addr 192.168.99.156

after this create the Nginx conf file

sudo mkdir -p /data/loadbalancer
sudo vi /data/loadbalancer/default.conf

and add following lines in this file

  server {
       listen 80;
       location / {
          proxy_pass http://backend;
       }
    }
    upstream backend {
       server 192.168.99.153:8080;
       server 192.168.99.154:8080;
    }

after this when I create an NGINX service with

docker service create --name loadbalancer --mount type=bind,source=/data/loadbalancer,target=/etc/nginx/conf.d --publish 80:80  nginx

When I launch the 192.168.99.156:80 on the browser, I see the 502 Bad Gateway error page.

Question:-

  1. Some time tomcat server is also not accessible after creating the backend service.

  2. Why tomcat is not coming up using NGINX load balancer?

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.