4

Every time I start or stop any Docker container, the /run/systemd/resolve/resolv.conf file on the host (Ubuntu 19.04) gets overwritten with:

# Generated by dhcpcd from enp30s0.dhcp
# /etc/resolv.conf.head can replace this line
nameserver 127.0.0.1
# /etc/resolv.conf.tail can replace this line

As a result, after every reboot and after any time a container is started or stopped, I have to issue netplan generate and netplan apply to fix the resolv.conf file.

How do I get docker to stop jacking up the host's resolv.conf file?

My netplan looks like this:

# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    renderer: networkd
    ethernets:
        enp30s0:
            addresses:
            - 10.0.10.20/24
            dhcp4: no
            gateway4: 10.0.10.1
            nameservers:
                addresses:
                - 10.0.10.1
    version: 2

When I run systemd-resolve --status:

Global
       LLMNR setting: no
MulticastDNS setting: no
  DNSOverTLS setting: no
      DNSSEC setting: no
    DNSSEC supported: no
         DNS Servers: 10.0.10.1

These are the various docker containers I have:

docker network create -d macvlan --subnet=10.0.10.0/24 --gateway=10.0.10.1 -o parent=enp30s0 macvlan-services-network


docker container create --name="pihole-kids" \
    --volume /opt/docker/volumes/pihole-kids/etc/pihole:/etc/pihole \
    --volume /opt/docker/volumes/pihole-kids/etc/dnsmasq.d:/etc/dnsmasq.d \
    --volume /opt/docker/volumes/pihole-kids/var/log/pihole.log:/var/log/pihole.log \
    --net macvlan-services-network \
    --ip 10.0.10.21 \
    --publish 53:53/tcp \
    --publish 53:53/udp \
    --publish 80:80 \
    --publish 443:443 \
    --dns=127.0.0.1 \
    --dns=10.0.10.20 \
    --add-host=restrict.youtube.com:216.239.38.120 \
    --add-host=restrictmoderate.youtube.com:216.239.38.119 \
    --add-host=forcesafesearch.google.com:216.239.38.120 \
    --add-host=strict.bing.com:204.79.197.220 \
    --add-host=safe.duckduckgo.com:34.243.144.154 \
    --env IPv6=False \
    --env ServerIP=10.0.10.21 \
    --env TZ="America/Chicago" \
    --restart=unless-stopped \
    pihole/pihole:latest



docker container create --name="pihole" \
    --volume /opt/docker/volumes/pihole/etc/pihole:/etc/pihole \
    --volume /opt/docker/volumes/pihole/etc/dnsmasq.d:/etc/dnsmasq.d \
    --volume /opt/docker/volumes/pihole/var/log/pihole.log:/var/log/pihole.log \
    --net=host \
    --env IPv6=False \
    --env ServerIP=10.0.10.20 \
    --env TZ="America/Chicago" \
    --dns=127.0.0.1 \
    --dns=10.0.10.1 \
    --restart=unless-stopped \
    pihole/pihole:latest


docker container create --name="emby-server" \
    --network="host" \
    --volume /opt/docker/volumes/emby/config:/config \
    --volume /mnt/media:/mnt/media \
    --device /dev/dri:/dev/dri \
    --runtime=nvidia \
    --publish 8096:8096 \
    --publish 8920:8920 \
    --env UID=997 \
    --env GID=997 \
    --env GIDLIST=1000 \
    --env NVIDIA_VISIBLE_DEVICES=all \
    --env NVIDIA_DRIVER_CAPABILITIES=compute,utility,video \
    emby/embyserver:latest


docker container create --name="nzbhydra2" \
    --volume /opt/docker/volumes/nzbhydra2/config:/config \
    --volume /mnt/Downloads:/mnt/Downloads \
    --volume /etc/localtime:/etc/localtime:ro \
    --publish 5076:5076 \
    --env UMASK=000 \
    --env PUID=1004 \
    --env PGID=1004 \
    binhex/arch-nzbhydra2


docker container create --name="portainer" \
    --volume /opt/docker/volumes/portainer/data:/data \
    --volume /var/run/docker.sock:/var/run/docker.sock \
    --publish 9000:9000 \
    --restart=always \
    portainer/portainer

3 Answers 3

2

FIGURED IT OUT!

At some point, dhcpcd was installed on my system. No idea why. Before I decided to remove it, I edited the /etc/dhcpcd.conf file and replaced the 127.0.0.1 with 10.0.10.1 to see if /etc/resolv.conf would change. I rebooted and it indeed changed. I removed dhcpcd with apt purge dhcpcd5, rebooted, and now the nameservers remain consistent with what I have in my netplan.

Hopefully this is helpful for someone else that goes through this same problem.

1
  • Thanks! If someone's actually using dhcpcd like me: you can use its allowinterfaces/denyinterfaces config option to prevent it from overwriting your resolv.conf every time new Docker network interface pops up.
    – che
    May 29, 2020 at 8:57
0

We just solved a similar issue. With every deployment of a docker container the DNS settings went back to an outdated setup.

The file /etc/resolv.conf pointed to # This file is managed by man:systemd-resolved(8). Do not edit.

Via systemd-resolve --status we found the wrong DNS settings in the network adapter, changed it in the config files in /etc/systemd/network and restarted the service via systemctl restart systemd-networkd.

After a docker stop/start everything worked fine.

-1

The workaround is to bind mount resolv.conf from host. Make sure that 127.0.0.11 is added on hosts’s resolv.conf.

Please make sure this workaround only works if you include 127.0.0.11 in hosts /etc/resolv.conf and copy this resolv.conf to docker compose file location.

volumes:

  • ./resolv.conf:/etc/resolv.conf
2
  • Please (1) explain how to do this (i.e., what commands to use) and (2) explain how it works.  Link to references, if possible. … … … … … … … … … … … … … … … … … … … Please do not respond in comments; edit your answer to make it clearer and more complete. Apr 7, 2022 at 23:29
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Apr 18, 2022 at 19:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .