Using docker names as DNS ips

im using a yml for docker stacks/swarm.

When using PIHOLE_DNS_1: cloudflared#5054 - this does not translate to the ip in the docker stack. Is this function only working in docker compose?

  pihole:
    image: pihole/pihole:latest
    hostname: pihole
    networks:
      - swarm
    ports:
      - target: 53
        published: 53
        protocol: udp
        mode: host
      - target: 53
        published: 53
        protocol: tcp
        mode: host
    environment:
      TZ: 'America/New_York'
      DNSSEC: 'True'
      PIHOLE_DNS_1: cloudflared#5054
      IPv6: 'False'
      DNSMASQ_LISTENING: 'all'
      DNS_BOGUS_PRIV: 'True'
      DNS_FQDN_REQUIRED: 'True'
      TEMPERATUREUNIT: 'F'
      VIRTUAL_HOST: 'pihole.domain.dev'
      SKIPGRAVITYONBOOT: 1
    volumes:
      - pihole:/etc/pihole
      - dnsmasqd:/etc/dnsmasq.d
    deploy:
      update_config:
        parallelism: 2
        delay: 0s
      labels:
        - "traefik.enable=true"
        - "traefik.http.routers.pihole.rule=Host(`pihole.domain.dev`)"
        - "traefik.http.routers.pihole.entrypoints=websecure"
        - "traefik.http.services.pihole.loadbalancer.server.port=80"
      replicas: 1
      placement:
        constraints:
          - node.role == manager

When looking at the env it does not translate. If the swarm updates i have to go in manually and edit the ip.

root@pihole:/# env
S6_BEHAVIOUR_IF_STAGE2_FAILS=2
HOSTNAME=pihole
S6_CMD_WAIT_FOR_SERVICES_MAXTIME=0
PWD=/
TEMPERATUREUNIT=F
TZ=America/New_York
DNS_FQDN_REQUIRED=True
HOME=/root
FTLCONF_LOCAL_IPV4=0.0.0.0
PIHOLE_DNS_1=cloudflared#5054
VIRTUAL_HOST=pihole.domain.dev
TERM=xterm
FTL_CMD=no-daemon
IPv6=False
SKIPGRAVITYONBOOT=1
PHP_ERROR_LOG=/var/log/lighttpd/error-pihole.log
SHLVL=1
phpver=php
DNSMASQ_USER=pihole
DNSMASQ_LISTENING=all
DNS_BOGUS_PRIV=True
DNSSEC=True
PATH=/opt/pihole:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
S6_KEEP_ENV=1
_=/usr/bin/env

Docker has it's own methods for resolving container names and that is completely separate from Pi-hole.

Yes but your documentations says it supports container names yet mine does not translate over. Specifically the PIHOLE_DNS_. Yet when setting it dns1 is empty in the gui with no resolution.

Check your envvars, it's PIHOLE_DNS_ without any ordinals.

If your issue is that the IP address of the container that cloudflared points to changes and the other containers do not get the new IP address then that's back down to Docker.

Edit: Can you also check /etc/resolv.conf inside the running containers to see what server they are using to resolve inside the docker network?

Edit2: Might be worth a look at /etc/hosts as well to see if anything is being written there.

PIHOLE_DNS_ was the issue i had it marked as PIHOLE_DNS_1. thanks

1 Like