Skip to content

HAProxy + Docker Setup Guide

HAProxy is really easy to run in docker. Let’s start by pulling the official docker image: docker pull haproxy.

docker hub

Setup Dockerfile

Create a dockerfile in your working directory. Our dockerfile is going to be very simple. Pull HAProxy and copy in our configuration file. Here’s an example:

					FROM haproxy:latest # you can also pin a specific version here
COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg

That’s all there is to it. Very simple and straightforward.

Ready to get the whole story on your uptime?
Status List delivers uptime checks with technical diagnostics in a one dashboard. A pass/fail isn’t the whole story.
Join over 2,000 companies and try it for free today.

Setup HAProxy Config

Next, create an haproxy.cfg file. Below is a sample you can start from. You can see our HAProxy configuration guide for more specific use-cases and setup instructions.

    log /log local0
    maxconn 4000
    mode http
    log global
    timeout client 30s
    timeout connect 10s
    timeout server 240s
frontend ft_web
    bind *:80
    mode http
    default_backend bk_web
backend bk_web
    balance leastconn
    server web_1 check
    server web_2 check

Running HAProxy in Docker

Next, build and run your container:

					docker build -t lb-haproxy .
docker run -d --name haproxy --sysctl net.ipv4.ip_unprivileged_port_start=0 -p 80:80 lb-haproxy

You can now send requests to port 80 on the host machine and they will be routed by HAProxy to your 2 backends.