I'm trying to set up my first homelab. I've already got a few services running as docker-containers and also got Traefik working with them. I now want to do the same with my PiHole instance. I've got it working so that I can access the dashboard by navigating to 'pihole.local.myurl.com/admin'. However, I would like to automatically add the '/admin' prefix.
I tried it with this docker-compose.yml, but the prefix won't be added:
version: "3"
# More info at https://github.com/pi-hole/docker-pi-hole/ and https://docs.pi-hole.net/
services:
pihole:
image: pihole/pihole:latest
container_name: pihole
restart: unless-stopped
# For DHCP it is recommended to remove these ports and instead add: network_mode: "host"
networks:
- proxy
ports:
- "53:53/tcp"
- "53:53/udp"
#- "67:67/udp" # Only required if you are using Pi-hole as your DHCP server
#- "8000:80/tcp"
environment:
TZ: 'Europe/Berlin'
WEBPASSWORD: 'my_password'
# Volumes store your data between container upgrades
volumes:
- './etc-pihole:/etc/pihole'
- './etc-dnsmasq.d:/etc/dnsmasq.d'
- './resolv.conf:/etc/resolv.conf'
labels:
- "traefik.enable=true"
- "traefik.http.routers.pihole.entrypoints=http"
- "traefik.http.routers.pihole.rule=Host(`pihole.local.myurl.com`)"
- "traefik.http.middlewares.pihole-prefix.addPrefix.prefix=/admin"
- "traefik.http.routers.pihole.middlewares=pihole-prefix"
- "traefik.http.middlewares.pihole-https-redirect.redirectscheme.scheme=https"
- "traefik.http.routers.pihole.middlewares=pihole-https-redirect"
- "traefik.http.routers.pihole-secure.entrypoints=https"
- "traefik.http.routers.pihole-secure.rule=Host(`pihole.local.myurl.com`)"
- "traefik.http.routers.pihole-secure.tls=true"
- "traefik.http.routers.pihole-secure.service=pihole"
- "traefik.http.services.pihole.loadbalancer.server.port=80"
- "traefik.docker.network=proxy"
# https://github.com/pi-hole/docker-pi-hole#note-on-capabilities
#cap_add:
# - NET_ADMIN # Recommended but not required (DHCP needs NET_ADMIN)
networks:
proxy:
external: true
Is there a mistake in my docker-compose?
You have to specify the location of the middleware. In this case, append @docker
to the end of the lines for the routers where you are calling the middlewares. (Label lines 5 and 7)
Eg: Here is my compose for Organizr calling both locally defined and separate file based middlewares:
- traefik.enable=true
## HTTP Routers
- traefik.http.routers.organizr-rtr.entrypoints=https
- traefik.http.routers.organizr-rtr.rule=Host(`$DOMAINNAME`) || Host(`www.$DOMAINNAME`)
## Middlewares
- traefik.http.routers.organizr-rtr.middlewares=organizr-redirect@docker,secure-headers@file
## Middlewares - Redirect to www
- traefik.http.middlewares.organizr-redirect.redirectregex.permanent=true
- traefik.http.middlewares.organizr-redirect.redirectregex.regex=^http(?:s)?://$DOMAINNAME/(.*)
- traefik.http.middlewares.organizr-redirect.redirectregex.replacement=https://www.$DOMAINNAME/$${1}
## HTTP Services
- traefik.http.routers.organizr-rtr.service=organizr-svc
- traefik.http.services.organizr-svc.loadbalancer.server.port=80