A robust, selfhost-ready Docker container combining HAProxy load balancing with Keepalived for high availability. This solution provides automatic failover capabilities and efficient load distribution for your services.
- High Availability: Automatic failover using Keepalived VRRP
- Load Balancing: Advanced load balancing with HAProxy
- Health Checks: Automated service health monitoring
- Easy Configuration: Simple environment variable configuration
- Alpine-based: Lightweight and secure base image
- Fixed Scale: 2 load balacing/failover deployments, serving 2 backend servers
- HAProxy stats: Near real-time feed of the proxied services
# Pull the image
docker pull peterweissdk/haproxy-keepalived
# Run with custom configuration
docker run -d \
--name haproxy-keepalived \
--cap-add=NET_ADMIN \
--cap-add=NET_BROADCAST \
--cap-add=NET_RAW \
--net=host \
--env-file=.env \
peterweissdk/haproxy-keepalived
# Run the container using the provided Docker Compose and .env file
docker compose up -d
| Variable | Description | Example |
TZ
: System Timezone - Europe/Berlin
| Variable | Description | Example |
VRRP_INSTANCE
: VRRP instance name - VI_1INTERFACE
: Network interface - eth0STATE
: Node state (MASTER/BACKUP) - MASTERPRIORITY
: Node priority (1-255) - 100ROUTER_ID
: Unique router ID - 50VIRTUAL_IPS
: Virtual IP address - 192.168.1.100/24UNICAST_SRC_IP
: Source IP for unicast - 192.168.1.11UNICAST_PEERS
: Peer IP address - 192.168.1.12
| Variable | Description | Example |
PROTOCOL_DEFAULT
: Default protocol - tcpTIMEOUT_CLIENT_DEFAULT
: Client timeout (seconds) - 10TIMEOUT_CONNECT_DEFAULT
: Timeout, connect to a backend server (seconds) - 5TIMEOUT_SERVER_DEFAULT
: Server timeout (seconds) - 10
| Variable | Description | Example |
NAME_FRONTEND
: Frontend name - ha-frontendPORT_FRONTEND
: Listen port - 5001PROTOCOL_FRONTEND
: Frontend protocol - tcpOPTION_FRONTEND
: Frontend options - tcplogDEFAULT_BACKEND
: Default backend name - ha-backend
| Variable | Description | Example |
NAME_BACKEND
: Backend name - ha-backendPROTOCOL_BACKEND
: Backend protocol - tcpOPTION_BACKEND
: Backend options - tcp-checkBALANCE_BACKEND
: Server scheduling - roundrubin
| Variable | Description | Example |
NAME_SERVER1
: Backend name - backend-server1IP_SERVER1
: Server IP address - 192.168.1.21PORT_SERVER1
: Listen port - 6001NAME_SERVER2
: Backend name - backend-server2IP_SERVER2
: Server IP address - 192.168.1.22PORT_SERVER2
: Listen port - 6002
# Clone the repository
git clone https://github.com/peterweissdk/haproxy-keepalived.git
# Build the image
cd haproxy-keepalived
docker build -t haproxy-keepalived .
.
├── conf/
│ ├── haproxy/
│ │ └── haproxy.cfg_tpl
│ ├── keepalived/
│ │ └── keepalived.conf_tpl
│ └── supervisor/
│ ├── haproxy.ini
│ └── keepalived.ini
├── .env
├── Dockerfile
├── docker-entrypoint.sh
├── supervisord.conf
├── healthcheck.sh
├── LICENSE
└── README.md
The container includes built-in health checks for both HAProxy and Keepalived services. Monitor the status using:
docker inspect --format='{{json .State.ExitCode}}' <container_name>
View the Docker health check logs with the following command:
docker inspect --format='{{json .State.Health}}' <container_name>
Contributions are welcome! Please feel free to submit a Pull Request.
If you encounter any issues or need support, please file an issue on the GitHub repository.
This project is licensed under the GNU GENERAL PUBLIC LICENSE v3.0 - see the LICENSE file for details.