Making permanent changes to resolv.conf

The issue I am facing:
When updating gravity I get the following errors, as per the thread linked below:

[✗] DNS resolution is currently unavailable*
[✗] DNS resolution is not available*

As discussed here:

I have solved the issue temporarily using the steps in the thread above, but when I restart the Docker container I lose the changes that I made to /etc/resolv.conf. I gather that this is expected behaviour, but how do I make these changes permanent? Also, I am running a fresh install of the official PiHole Docker container, so why has this problem happened? I guess I must have got the config wrong somewhere...?

Details about my system:
Official PiHole image running in Docker with default settings.

What I have changed since installing Pi-hole:
Nothing, other than the changes to resolv.conf detailed in the linked thread.

Please share your docker-compose.yml or docker run command.

My docker-compose file is as follows:

version: "3"

# More info at https://github.com/pi-hole/docker-pi-hole/ and https://docs.pi-hole.net/
services:
  pihole:
    container_name: pihole
    image: pihole/pihole:latest
    hostname: piholevm
    ports:
#host:container
      - "53:53/tcp"
      - "53:53/udp"
      - "67:67/udp"
      - "8282:80/tcp"
      - "443:443/tcp"
    environment:
      TZ: 'Europe/London'
      WEBPASSWORD: REDACTED
      PIHOLE_DNS_: '127.0.0.1;1.1.1.1'
    # Volumes store your data between container upgrades
    volumes:
      - './etc-pihole/:/etc/pihole/'
      - './etc-dnsmasq.d/:/etc/dnsmasq.d/'
    # Recommended but not required (DHCP needs NET_ADMIN)
    #   https://github.com/pi-hole/docker-pi-hole#note-on-capabilities
    cap_add:
      - NET_ADMIN
    restart: unless-stopped

I'd probably start by changing the Docker host systems DNS server settings.

You are not setting any specific DNS server for the container, so your hosts machine's DNS servers should propagate into your container automatically, i.e. your hosts DNS settings should be picked up upon container creation.

You could also try to add specific DNS servers by adding lines similar like the following to pihole:

    dns:
      - 127.0.0.1
      - 1.1.1.1

Be aware though that this sporadically was causing issues in the past, where some Docker installations would refuse starting a container when 127.0.0.1 would not be the first in list, while others did so when it wasn't the last, and still others didn't complain either way.

Thank you for your quick reply. When you say "start by changing the Docker host system's DNS server settings" do you mean that I should set the Docker host to use the Pihole as its DNS server or will this create some sort of weird situation where the host won't have a DNS server until the Pihole container has finished booting?

With regards to changing the docker-compose file is my usage of PIHOLE_DNS_: '127.0.0.1;1.1.1.1' incorrect, then?

Thanks again

I obviously missed commenting on them - thank you for reminding me.

Those are Pi-hole's upstream DNS servers.
The localhost address 127.0.0.1 should be avoided there.

The same is probably true for your Docker host system's DNS servers, as localhost would mean differerent recipients on the host and inside a container, unless you were using Docker's host network mode.

Thank you for clearing up my upstream misunderstanding.

I have resolved the issue by adding your DNS suggestion to my docker-compose file and adjusting my upstream servers appropriately.

For anyone visiting this thread in future, my working docker-compose is below:

version: "3"

# More info at https://github.com/pi-hole/docker-pi-hole/ and https://docs.pi-hole.net/
services:
  pihole:
    container_name: pihole
    image: pihole/pihole:latest
    hostname: piholevm
    ports:
#host:container
      - "53:53/tcp"
      - "53:53/udp"
      - "67:67/udp"
      - "8282:80/tcp"
      - "443:443/tcp"
    #Container DNS
    dns:
      - 127.0.0.1
      - 192.168.1.1
      - 1.1.1.1
    environment:
      TZ: 'Europe/London'
      WEBPASSWORD: REDACTED
      #Upstream DNS
      PIHOLE_DNS_: '1.1.1.1'
    # Volumes store your data between container upgrades
    volumes:
      - './etc-pihole/:/etc/pihole/'
      - './etc-dnsmasq.d/:/etc/dnsmasq.d/'
    # Recommended but not required (DHCP needs NET_ADMIN)
    #   https://github.com/pi-hole/docker-pi-hole#note-on-capabilities
    cap_add:
      - NET_ADMIN
    restart: unless-stopped

Many thanks for all your help.

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