What's new
PGBlitz.com

Register Now! Find useful tips, Interact /w Community Members and join the part the Best Community on the Internet!

PiHole with docker/traefik tutorial

Assists Greatly with Development Costs

CyborgPirate

Blitz 1st Class
Hey guys,
I came across this tutorial for getting pi hole working with a traefik and docker and thought others might be interested.
https://www.smarthomebeginner.com/run-pihole-in-docker-on-ubuntu-with-reverse-proxy/

I haven't tried it out yet but it looks pretty comprehensive.

I was thinking of trying to get it working with wireguard which I have already running on my PlexGuide server for a remote encrypted VPN with an adblocker built in.

Any thoughts?
 

crustyakorn

Blitz 2nd Class
Would be nice to set up this app on PGBlitz.

Can it be done in a way that Docker exposes this container to get its' own IP address of the subnet/modem/router? This way i could point my devices to use the DNS Server IP from the "dedicated" container.
 

Sejrup

Blitz 1st Class
I made this work using the guide from the webpage. I made it work using Docker Compose though. Will try to take a look at converting the docker-compose.yml file to ansible so that in can be uploaded to the community repo.

Let me know if you have any questions. I know nothing about Linux, but am quite stubborn ?
 

Admin9705

Administrator
Project Manager
I made this work using the guide from the webpage. I made it work using Docker Compose though. Will try to take a look at converting the docker-compose.yml file to ansible so that in can be uploaded to the community repo.

Let me know if you have any questions. I know nothing about Linux, but am quite stubborn ?
Ya but treafik will be the problem. If you figure it, that would be awesome
 

captngimpy

Blitz Sergeant
Staff
I knew pihole had been talked about earlier and I was running through my monthly expenses and I have one vps I use for pihol mostly(cause it was cheap and I'm a sucker for a deal) but anything I can cut out (spring cleaning is coming) and run off my dedicated server through docker would be great.
 

Admin9705

Administrator
Project Manager
Yes, it appears to be working with Traefik. I have the certs on the domain pihole.example.com and can route all traffic through the DNS (y) Will do a bit more testing today if I have time.
awesome great to know
 

PonsterManda

Blitz 3rd Class
Yes, it appears to be working with Traefik. I have the certs on the domain pihole.example.com and can route all traffic through the DNS (y) Will do a bit more testing today if I have time.
You mean making use of an alternative DNS server for your DNS queries. Pihole isnt routing all traffic ;)
 

Sejrup

Blitz 1st Class
In case anyone wants to give it a try, I have posted my yaml code below. Just copy/paste contents to pihole.yml and upload to the /opt/mycontainers folder. Then you can install it via PG Box and Community.

I did perform the initial steps outlined in the guide that OP linked to. Not entirely sure if needed though. As far as I can tell network-manager is not installed per default in 18.0.4 so I installed that manually. There was a lot of back and forth for me initially so I kind of lost track a bit of what is needed in order to make it work. I think I might have added a nameserver in /etc/resolv.conf because I couldn't resolve any addresses after disabling and stopping Ubuntu’s DNS resolver.

A few things should be modified according to your needs

ServerIP: '192.168.1.10'
WEBPASSWORD: 'PIHOLEWEBPASSWORD'
DNS2: '1.1.1.1' - In case you want to use a different DNS server than Cloudflare

I havent quite figured out how to push it to the Github repo yet. Maybe also best to wait until someone besides me tries it out :)

YAML:
#!/bin/bash
#
# Title:      PGBlitz (Reference Title File)
# Author(s):  Admin9705
# URL:        https://pgblitz.com - http://github.pgblitz.com
# GNU:        General Public License v3.0
################################################################################
---
- hosts: localhost
  gather_facts: false
  tasks:
    # FACTS #######################################################################
    - name: 'Set Known Facts'
      set_fact:
        pgrole: 'pihole'
        intport: '53/tcp'
        extport: '53'
        intport2: '53/udp'
        extport2: '53'
        intport3: '80'
        extport3: '8182'
        intport4: '443'
        extport4: '8183'
        image: 'pihole/pihole:latest'

    # CORE (MANDATORY) ############################################################
    - name: 'Including cron job'
      include_tasks: '/opt/coreapps/apps/_core.yml'

    # LABELS ######################################################################
    - name: 'Adding Traefik'
      set_fact:
        pg_labels:
           traefik.enable: 'true'
           traefik.backend: '{{pgrole}}'
           traefik.frontend.rule: 'HostRegexp:{{pgrole}}.{{domain.stdout}},{{tldset}},{catchall:.*}'
           traefik.frontend.priority: '1'
           traefik.frontend.headers.SSLRedirect: 'true'
           traefik.frontend.headers.STSSeconds: '315360000'
           traefik.frontend.headers.browserXSSFilter: 'true'
           traefik.frontend.headers.contentTypeNosniff: 'true'
           traefik.frontend.headers.forceSTSHeader: 'true'
           traefik.frontend.headers.SSLHost: '{{domain.stdout}}'
           traefik.frontend.headers.STSIncludeSubdomains: 'true'
           traefik.frontend.headers.STSPreload: 'true'
           traefik.frontend.headers.frameDeny: 'true'
           traefik.frontend.auth.forward.address: '{{gauth}}'
           traefik.port: '{{intport3}}'

    - name: 'Setting PG Volumes'
      set_fact:
        pg_volumes:
          - '/opt/appdata/pihole/{{pgrole}}:/etc/pihole'
          - '/opt/appdata/{{pgrole}}/dnsmasq.d:/etc/dnsmasq.d'
          - '/etc/localtime:/etc/localtime:ro'

    - name: 'Setting PG ENV'
      set_fact:
        pg_env:
          PUID: '1000'
          PGID: '1000'
          ServerIP: '192.168.1.10'
          PROXY_LOCATION: '{{pgrole}}'
          VIRTUAL_HOST: '{{pgrole}}.{{domain.stdout}}'
          VIRTUAL_PORT: '{{intport3}}'
          TZ: '${TZ}'
          WEBPASSWORD: 'PIHOLEWEBPASSWORD'
          DNS1: '127.0.0.1'
          DNS2: '1.1.1.1'

    # MAIN DEPLOYMENT #############################################################
    - name: 'Deploying {{pgrole}}'
      docker_container:
        name: '{{pgrole}}'
        image: '{{image}}'
        pull: yes
        published_ports:
          - '{{ports.stdout}}{{extport}}:{{intport}}'
          - '{{ports.stdout}}{{extport2}}:{{intport2}}'
          - '{{ports.stdout}}{{extport3}}:{{intport3}}'
          - '{{ports.stdout}}{{extport4}}:{{intport4}}'
        volumes: '{{pg_volumes}}'
        env: '{{pg_env}}'
        restart_policy: unless-stopped
        networks:
          - name: plexguide
            aliases:
              - '{{pgrole}}'
        state: started
        labels: '{{pg_labels}}'
 

Sejrup

Blitz 1st Class
Check out the following post in the "What Docker would you like to have created" for a working .yml file for pi-hole.
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

Similar threads


Development Donations

 

Trending

Top