https://github.com/peterweissdk/keepalived
Docker container for running Keepalived with VRRP
https://github.com/peterweissdk/keepalived
docker dockerfile
Last synced: about 1 month ago
JSON representation
Docker container for running Keepalived with VRRP
- Host: GitHub
- URL: https://github.com/peterweissdk/keepalived
- Owner: peterweissdk
- License: gpl-3.0
- Created: 2025-01-15T21:46:56.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-09-28T13:49:15.000Z (4 months ago)
- Last Synced: 2025-09-28T15:51:40.061Z (4 months ago)
- Topics: docker, dockerfile
- Language: Dockerfile
- Homepage:
- Size: 54.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 💾 Keepalived Docker Container
[](https://docker.com/)
[](https://www.alpinelinux.org/)
[](https://keepalived.org/)
[](https://www.gnu.org/licenses/gpl-3.0.en.html/)
A lightweight, Alpine-based Docker container for running Keepalived with VRRP (Virtual Router Redundancy Protocol) support.
## ✨ Features
- **Alpine-based**: Lightweight and secure base image
- **VRRP support**: High availability with Virtual Router Redundancy Protocol (VRRP)
- **Easy Configuration**: Configure Keepalived using environment variables, and service check-scripts
- **Health Checks**: Monitor service health with built-in Docker health checks
## 🚀 Quick Start
Run the container:
```bash
# Pull the image
docker pull peterweissdk/keepalived
# Run with custom configuration
docker run -d \
--name keepalived \
--restart=unless-stopped \
--cap-add=NET_ADMIN \
--cap-add=NET_BROADCAST \
--cap-add=NET_RAW \
--net=host \
--env-file .env \
keepalived:latest
# Run the container using the provided Docker Compose and .env file
docker compose up -d
```
## 🔧 Configuration
### Environment Variables
| Variable | Description | Example |
|------------------|---------------------------------------------|-------------------|
| `TZ` | Container timezone | Europe/Copenhagen |
| `VRRP_INSTANCE` | VRRP instance name | VI_1 |
| `INTERFACE` | Network interface | eth0 |
| `STATE` | Node state (MASTER/BACKUP) | MASTER |
| `PRIORITY` | Node priority (1-255) | 100 |
| `ROUTER_ID` | Unique router ID | 52 |
| `VIRTUAL_IPS` | Virtual IP address with subnet mask | 192.168.1.100/24 |
| `UNICAST_SRC_IP` | Source IP for unicast communication | 192.168.1.101 |
| `UNICAST_PEERS` | Peer IP addresses for unicast communication | 192.168.1.102 |
| `WEIGHT` | Weight for tracked scripts | 50 |
| `FALL` | Number of failures before transition | 2 |
| `RISE` | Number of successes before transition | 2 |
### Required Capabilities
- NET_ADMIN: For network interface configuration
- NET_BROADCAST: For VRRP advertisements
- NET_RAW: For raw socket access
### Service Check-Script
Create a script to run at regular intervals to check the state of your service. Create a bind mount and copy the script into it
- Name of script: check-script.sh
- Bind mount point: /usr/local/scripts/
- Runs at regular intervals: 2 seconds
## 🏗️ Building from Source
```bash
# Clone the repository
git clone https://github.com/peterweissdk/keepalived.git
cd keepalived
# Build the image
docker build -t keepalived:latest .
```
## 📝 Directory Structure
```bash
keepalived/
├── conf/
│ └── keepalived.conf_tpl
├── scripts/
│ └── check_and_run.sh
├── .github/
├── .env
├── Dockerfile
├── docker-entrypoint.sh
├── healthcheck.sh
├── docker-compose.yml
├── LICENSE
└── README.md
```
## 🔍 Health Check
The container includes a comprehensive health check system that monitors:
1. Keepalived Process Status
- Verifies the keepalived daemon is running
2. Virtual IP environment variable
- Verifies the VIRTUAL_IPS environment variable is set
View health status:
```bash
docker inspect --format='{{.State.Health.Status}}' keepalived
```
View detailed health check history:
```bash
docker inspect --format='{{json .State.Health}}' keepalived | jq
```
Watch health status in real-time:
```bash
watch -n 5 'docker inspect --format="{{.State.Health.Status}}" keepalived'
```
## 🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
## 🆘 Support
If you encounter any issues or need support, please file an issue on the GitHub repository.
## 📄 License
This project is licensed under the GNU GENERAL PUBLIC LICENSE v3.0 - see the [LICENSE](LICENSE) file for details.