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:-
Some time tomcat server is also not accessible after creating the backend service.
Why tomcat is not coming up using NGINX load balancer?