After following the steps below you should be able to browse to site1.org
and site2.org
in your default web browser and see the HAProxy woking. If you are not sure what a reverse proxy is and when to use it check out this post for further information.
A overlay network has to be created first using the following command:
docker network create --driver overlay --scope swarm proxy
docker stack deploy -c proxy\docker-compose.haproxy.yml proxy
docker stack deploy -c viz\docker-compose.viz.yml viz
docker stack deploy -c site1\docker-compose.web.yml site1
docker stack deploy -c site1\docker-compose.web.yml site2
Add the host site1.org
and site2.org
to your hosts file.
On windows 10 the hosts files is under: C:\Windows\System32\drivers\etc
On a mac the hosts file is under: /private/etc
Add the following lines.
127.0.0.1 site1.org
127.0.0.1 site2.org
127.0.0.1 viz.org
HAProxy offers a nice stats page. Open your browser and navigate to localhost:1936
. It uses basic auth for seccurity. Default username and password is stats:stats
It is now possible to scale your webservice to as many containers as needed. HAProxy will take care of load balancing all of them.
docker service scale site1_app=5
or
docker service scale site2_app=3