services:
  unbound:
    image: mvance/unbound:latest
    container_name: unbound-pihole-rpi4
    network_mode: host
    restart: unless-stopped
    environment:
      TZ: ${TZ}
      UNBOUND_PORT: "5335"
    volumes:
      - ${APPDATA_UNBOUND_ROOT}:/opt/unbound/etc/unbound/
    healthcheck:
      test: ["CMD-SHELL", "hex=$$(printf '%04X' \"$$UNBOUND_PORT\"); grep -qi \":$$hex\" /proc/net/tcp /proc/net/tcp6 || exit 1"]
      interval: 30s
      timeout: 10s
      retries: 6
      start_period: 20s

  pihole:
    image: pihole/pihole:latest
    container_name: pihole-rpi4
    network_mode: host
    restart: unless-stopped
    depends_on:
      unbound:
        condition: service_healthy
    environment:
      TZ: ${TZ}
      PIHOLE_WEB_PORT: ${RPI4_PIHOLE_WEB_PORT}
      FTLCONF_webserver_api_password: ${PIHOLE_PASSWORD}
      FTLCONF_dns_listeningMode: "LOCAL"
      FTLCONF_dns_upstreams: "127.0.0.1#5335"
      FTLCONF_webserver_port: ${RPI4_PIHOLE_WEB_PORT}
    volumes:
      - ${APPDATA_PIHOLE_ROOT}/etc-pihole:/etc/pihole
      - ${APPDATA_PIHOLE_ROOT}/etc-dnsmasq.d:/etc/dnsmasq.d
    cap_add:
      - SYS_NICE
