Public | Automated Build

Last pushed: 2 years ago
Short Description
CentOS 6.6 based Customizable HaProxy Container - 279.4 MB
Full Description

HaProxy Container Build

Built from appcontainers/centos66

Build container using default values.

docker build -t appcontainers/haproxy .

Running the container

The container is built to allow several configurable variables to be passed in at runtime. The values are as follows:

  • DOMAIN1 - This is the resolvable name of the first site that haproxy will be configured to Load Balance. (Do not include www)
  • DOMAIN2 - This is the resolvable name of the second site that haproxy will be configured to Load Balance. (Do not include www)
  • DOMAIN3 - This is the resolvable name of the third site that haproxy will be configured to Load Balance. (Do not include www)
  • DOMAIN4 - This is the resolvable name of the forth site that haproxy will be configured to Load Balance. (Do not include www)
  • DOMAIN5 - This is the resolvable name of the fifth site that haproxy will be configured to Load Balance. (Do not include www)
  • SITE1 - This is the resolvable server name of the server running the first site that haproxy will be configured to Load Balance.
  • SITE2 - This is the resolvable server name of the server running the second site that haproxy will be configured to Load Balance.
  • SITE3 - This is the resolvable server name of the server running the third site that haproxy will be configured to Load Balance.
  • SITE4 - This is the resolvable server name of the server running the forth site that haproxy will be configured to Load Balance.
  • SITE5 - This is the resolvable server name of the server running the fifth site that haproxy will be configured to Load Balance.

Note: If using links between the haproxy server and the front end web server, then the values of SITE1-5 will simply be the link name. If using a discovery system such as skydock or consul, then SITE1-5 will be the fully qualified domain name of the server in the skydock/consul namespace.

Run the container using default values

docker run -d -it --name haproxy -h haproxy -p 80:80 -p 443:443 --link webserver1:webserver1 -e DOMAIN1="test.com" -e SITE1="webserver1" appcontainers/haproxy

This will assume the following

  • DOMAIN1 = ""
  • DOMAIN2 = ""
  • DOMAIN3 = ""
  • DOMAIN4 = ""
  • DOMAIN5 = ""
  • SITE1 = ""
  • SITE2 = ""
  • SITE3 = ""
  • SITE4 = ""
  • SITE5 = ""

This container is configured so that every time it is started, it will ping the values of SITE1-5. For the sites that a response was recieved, the application will configure itself for that site, using the IP that the container running the site is currently using. If no SITE variable is supplied it will not configure that site in the haproxy config file.

In the following example, we will assume I am running 2 webservers ran via the following docker commands:

docker run -it --name wordpress1 -h wordpress1 -e APP_NAME="testapp1.com" -e APACHE_SVRALIAS='www.testapp1.com localhost' appcontainers/wordpress

docker run -it --name wordpress2 -h wordpress2 -e APP_NAME="testapp2.com" -e APACHE_SVRALIAS='www.testapp2.com localhost' appcontainers/wordpress

The above statements would run the appcontainers wordpress image, nameing the servers wordpress1 and wordpress2 respectivly, and would set up the servers to run the testapp1 and testapp2 domains. Port 80 would be exposed, but not published, and the rest of the container would accecpt the default values as specified via the appcontianers/wordpress documentation.

Run the haproxy container substituting the $varables with your own custom values

docker run -d -it \
--name haproxy \
-h haproxy \
-p 80:80 \
-p 443:443
--link wordpress1:wordpress1
--link wordpress2:wordpress2
-e DOMAIN1='testapp1.com' \
-e SITE1='wordpress1' \
-e DOMAIN2='testapp2.com' \
-e SITE2='wordpress2' \
appcontainers/haproxy

Running the above statement, would run the container, which would configure the following haproxy rule

acl is_wordpress1 hdr_end(host) -i testapp1.com
acl is_wordpress1 hdr_end(host) -i www.testapp1.com
acl is_wordpress2 hdr_end(host) -i testapp2.com
acl is_wordpress2 hdr_end(host) -i www.testapp2.com

use_backend wordpress1 if is_wordpress1
use_backend wordpress2 if is_wordpress2

backend wordpress1
    balance roundrobin
    option httpclose
    option forwardfor
    server wordpress1 172.17.0.10:80 maxconn 50

backend wordpress2
    balance roundrobin
    option httpclose
    option forwardfor
    server wordpress2 172.17.0.11:80 maxconn 50

Navigate to the FQDN of the server to ensure that haproxy is configurd correctly and forwarding port 80 traffic through to the front end webserver

SSL support is not dynaically built in as certificates will need to reside, and be configured on the haproxy server, although the haproxy rpm was build with and will support SSL once configured

Docker Pull Command
Owner
appcontainers
Source Repository