We have two instance of the application running on 192.168.1.250:2221 and
192.168.1.250:3331
Requests coming to the nginx server on port 8080 will be forwarded to the two
instances in a round robbin fashion.
Write a nginx configuration nginx.conf
http {
upstream all {
server 192.168.1.250:2221;
server 192.168.1.250:3331;
}
server {
listen 8080;
location / {
proxy_pass http://all/;
}
}
}
events { }
Dockerfile dockerfile
FROM nginx
COPY nginx.conf /etc/nginx/nginx.conf
Write the command
mkdir nginx-load-balancer
cd nginx-load-balancer
nano nginx.conf
nano dockerfile
docker build -t nginxlb .
docker run -d --name nginx-load-balancer -p 8087:8080 nginxlb