Load Balancing Containers docker

Load Balancing Containers docker

1) webserver

in this tutorial, we will use NGINX as a web server for load balancing configuration when containers are triggered

2) properties required to be configured when launching the proxy container

  • we need to bind the container to 80 by -p 80:80 command
  • we should mount the file called docker.sock file by using **-v /var/run/docker.sock:/tmp/docker.sock:ro.** We specify :ro to restrict access to read-only.
  • to run multiple websites on a single machine we have to set a hostname bash(-e DEFAULT*HOST=<domain>)
3)we will use NGINX proxy as example
docker run -d -p 80:80 -e DEFAULT_HOST=proxy.example -v /var/run/docker.sock:/tmp/docker.sock:ro --name
xxx6 nginx:latest

here we are using DEFAULT HOST any requests which come are redirected to the default container

docker run -d -p 80 -e VIRTUAL_HOST=proxy.example apache2:latest

VIRTUAL_HOST environment variable. This variable defines the domain where requests will come from and should be handled by the container.

so we launch the second container now the first request goes to the first container and the second request goes to the second container

docker run -d -p 80 -e VIRTUAL_HOST=proxy.example apache2:latest

the default Nginx configuration is generated inside the Nginx container

docker exec xxx6 cat /etc/nginx/conf.d/default.conf

to check the logs for load balancing

docker logs <containername> docker logs xxx6
Last updated on by vishal devxo