Simple Load Balancing for Docker Containers
Load balancing your web applications is important if you are growing (or have spikes of) traffic. Here’s how to set up a very simple load balanced solution in Docker Containers using HA Proxy.
For illustrative purposes we’ll keep it simple. Our application is a PHP webapp that makes a REST call to a Java REST API. We want to load balance the PHP App accross two containers while we have a single REST container.
This is a fairly artificial environment since all of our containers are running on the same host so we are not providing any form of scalabilty or failover. However, it’s a good first step in exploring our load balancing options.
I’m going to use the tutum/haproxy container from Docker Registry. This is a great pre-configured container available from the Docker Registry. It provides a wealth of configuration options, but I’m just going to use it in its default configuration. Furthermore, I’m not going to provide any form of dynamic discovery for my webapp containers. This is another limitation in that we can’t dynamically add new webapp containers. Again, this is a good first step, not an end goal.
Deploying the App
To deploy our application without load balancing we run the following two commands.
NOTE: For full details on how to build the containers see the readme.md file in GitHub:
In order to add load balancing we run the following:
We now have a web application load balanced across two containers, each of which talk to a single REST API container.
- Searching for a Cure for Cancer with Docker and Azure
- Load Balancing for Docker Containers with HA Proxy
- Readme Files That Are Also Slide Decks
- Create a Simple Swarm Cluster on Azure with ARM
- Getting Started With Docker Swarm on Azure
- Install Docker and Docker Machine
- Mounting Volumes in Boot2Docker on Hyper-V
- Using Docker Machine to create a Docker Host on Azure
- Experiments With Development Using Docker
- Dockerizing a Jekyll Site