Sample haproxy.cfg
# Simple configuration for an HTTP proxy listening on port 80 on all # interfaces and forwarding requests to a single backend "servers" with a # single server "server1" listening on 127.0.0.1:8000 global daemon maxconn 256 defaults mode http timeout connect 5000ms timeout client 50000ms timeout server 50000ms frontend http-in bind *:12345 default_backend servers backend servers server server1 192.168.1.161:80 maxconn 32 server server2 192.168.1.82:80 maxconn 32
Docker Setup
Sample script to build an HAProxy Container using the haproxy.cfg file copied to a subfolder named 'conf'.
buildDocker.sh
CONTAINER=haproxy IMAGE=haproxy:1.9.4 DIR=`pwd -P` docker stop $CONTAINER docker rm $CONTAINER docker run -d \ --net host \ --restart=always \ -v $DIR/conf:/usr/local/etc/haproxy:ro \ --name $CONTAINER \ $IMAGE docker logs -f $CONTAINER