"extra_hosts" not working correctly

I am using the docker image in combination with nginx-proxy, using the following docker-compose.yml on a raspberry pi 5:

version: "3"

services:
  nginx-proxy:
    container_name: nginx-proxy
    image: nginxproxy/nginx-proxy
    ports:
      - '80:80'
    environment:
      DEFAULT_HOST: pihole.server.local
    volumes:
      - '/var/run/docker.sock:/tmp/docker.sock'
    restart: always

  pihole:
    container_name: pihole
    image: pihole/pihole:latest
    hostname: pihole 
    ports:
      - "53:53/tcp"
      - "53:53/udp"
      - "8053:80/tcp"
    environment:
      DNSMASQ_LISTENING: 'all'
      VIRTUAL_HOST: pihole.server.local
      VIRTUAL_PORT: 80
    volumes:
      - './etc-pihole:/etc/pihole'
      - './etc-dnsmasq.d:/etc/dnsmasq.d'
    extra_hosts:
      - 'server.local:192.168.1.112'
      - 'pihole pihole.server.local:192.168.1.112'
    restart: always

Expected Behaviour:

When accessing pihole.server.local I should be referred to 192.168.1.112:8053, the same for server.local.

Actual Behaviour:

pihole.server.local doesn't work at all, but server.local does.

Debug Token:

Can't find out how to get one of these.

I don't think you can do two hosts in a single line like this. The docker compose specifications say:

Short syntax uses plain strings in a list. Values must set hostname and IP address for additional hosts in the form of HOSTNAME=IP.

I copied that line from the pihole docker nginx proxy example.
Does adding these extra_hosts automatically add them to the pi-hole's DNS records?

All extra_hosts does is add that line to the containers /etc/hosts file.

The example file is a community provided file that is many years old.

Can you explain more what you mean by "doesn't work"? What errors are you getting, what pages are you seeing? Is the problem that you can not resolve pihole.server.local or is the problem that you are not seeing the admin page but another page?

Oh sorry, I thought that file was an official one. I expected that adding the extra_hosts was all I needed to do to add these subdomains as DNS records.
After adding pihole.server.local to the DNS records of pi-hole I could reach the admin page and everything is working as expected. So if I need to manually enter the subdomains in pi-hole, do I also need to add them to the extra_hosts? Is pi-hole using these records?

I don't know. I don't use nginx proxy so I can't say what works or doesn't work for that particular setup.

Try removing the lines and see? You can't really break anything and if it doesn't work then put the lines back.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.