# Brug Pi-hole's officielle image som base
FROM pihole/pihole:latest
# Installer Unbound, Keepalived og Nano
RUN apt-get update && \
apt-get install -y \
unbound \
keepalived \
nano \
&& rm -rf /var/lib/apt/lists/*
# Kopier konfigurationsfiler for Keepalived og Unbound fra lokal mappe
COPY ./keepalived.conf /etc/keepalived/keepalived.conf
COPY ./unbound.conf /etc/unbound/unbound.conf
# Start Unbound og Keepalived i baggrunden og Pi-hole i foreground
CMD sh -c "unbound -d & keepalived -n -l -D & pihole start"
I am almost sure this will fail. My test with Pi-hole and Keepalived in their containers didn't work because Keepalives are using Pi-hole's network because of the failover.
Got it work now with a work around.
Probably not the right way to due it, but it is working.
#!/bin/bash
set -e
echo "Checking configuration files and services..."
# Make sure necessary configuration files exist
if [ ! -f /etc/keepalived/keepalived.conf ]; then
echo "Missing Keepalived configuration file! Exiting."
exit 1
fi
if [ ! -f /etc/unbound/unbound.conf ]; then
echo "Missing Unbound configuration file! Exiting."
exit 1
fi
# Start Unbound in the background
echo "Starting Unbound DNS resolver..."
unbound -d &
# Start Keepalived in the background
echo "Starting Keepalived..."
keepalived -n -l -D &
# Wait for Pi-hole's setupVars.conf to be ready (e.g. on first boot)
while [ ! -f /etc/pihole/setupVars.conf ]; do
echo "Waiting for setupVars.conf..."
sleep 1
done
# Remove existing pihole-FTL.db if necessary
if [ -f /etc/pihole/pihole-FTL.db ]; then
echo "Removing existing pihole-FTL.db..."
rm /etc/pihole/pihole-FTL.db
fi
# Start Pi-hole
echo "Starting Pi-hole..."
exec /s6-init