Step-by-Step Install Guide for Pihole with Traefik on Docker Swarm

GitHub-logo.pnglogo.png

68747470733a2f2f70692d686f6c652e6769746875622e696f2f67726170686963732f566f727465782f566f727465785f776974685f746578742e706e67.png

This guide will walk you through setting up Pi-hole, a powerful network-wide ad blocker, on a Docker Swarm with Traefik as the reverse proxy. We will use Docker to deploy Pi-hole and Traefik for secure and managed access.

Prerequisites

Step 1: Prepare the Directory Structure

To ensure persistent storage for Pi-hole, we will create directories on the shared GlusterFS mount:

mkdir /mnt/glustermount/data/pihole_data
mkdir /mnt/glustermount/data/pihole_data/dns
mkdir /mnt/glustermount/data/pihole_data/etc

These directories will store Pi-hole's configuration files and DNS settings.

Step 2: Create the docker-compose.yml File

In your working directory, create a docker-compose.yml file with the following content:

version: '3'

services:
  pihole:
    networks:
      - management_net  # For management via Traefik
    image: pihole/pihole:latest
    ports:
      - "53:53/tcp"
      - "53:53/udp"
      - "888:80"
    environment:
      TZ: 'Europe/Zurich'
      WEBPASSWORD: '${PIHOLE_PASSWORD}'
    volumes:
      - '/mnt/glustermount/data/pihole_data/etc:/etc/pihole'
      - '/mnt/glustermount/data/pihole_data/dns:/etc/dnsmasq.d'
    restart: unless-stopped
    deploy:
      mode: replicated
      replicas: 1
      placement:
        constraints: [node.platform.os == linux]
      labels:
        - 'traefik.enable=true'
        - "traefik.http.services.pihole.loadbalancer.server.port=888"
networks:
  management_net:
    external: true

Step 3: Deploy the Stack

Deploy the Stack: Use the following command to deploy Pi-hole with Traefik in Docker Swarm.

docker stack deploy -c docker-compose.yml pihole

Step 4: Access Pi-hole Web Interface

After the deployment completes, you can access Pi-hole's admin interface by navigating to https://pihole.local/admin in your browser. Log in with the password you specified in the environment variable (PIHOLE_PASSWORD).

Step 5: Update DNS Settings

To start using Pi-hole, configure your router or devices to use your Pi-hole instance as the DNS server. The IP address of your Pi-hole service is the one assigned by Docker, which you can retrieve using:

docker service ps pihole_pihole

OR if you use Keepalived you can use your VIP.


Conclusion

Setting up Pi-hole in a Docker Swarm environment with Traefik as a reverse proxy provides network-wide ad blocking, improving privacy and performance for all devices connected to your network. By leveraging Docker Swarm and Traefik, you achieve high availability, flexibility, and ease of management for your Pi-hole deployment.


Revision #10
Created 8 September 2024 17:55:02 by aeoneros
Updated 10 October 2024 23:16:00 by aeoneros