This page looks best with JavaScript enabled

Using Nginx container as a load balancer

 ·  β˜• 1 min read

We have two instance of the application running on and
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 {
         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

Ohidur Rahman Bappy
Ohidur Rahman Bappy
πŸ“šLearner 🐍 Developer