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
# /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}
    renderer: networkd
            dhcp4: no
    version: 2

When I run systemd-resolve --status:

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

These are the various docker containers I have:

docker network create -d macvlan --subnet= --gateway= -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 \
    --publish 53:53/tcp \
    --publish 53:53/udp \
    --publish 80:80 \
    --publish 443:443 \
    --dns= \
    --dns= \
    --add-host=restrict.youtube.com: \
    --add-host=restrictmoderate.youtube.com: \
    --add-host=forcesafesearch.google.com: \
    --add-host=strict.bing.com: \
    --add-host=safe.duckduckgo.com: \
    --env IPv6=False \
    --env ServerIP= \
    --env TZ="America/Chicago" \
    --restart=unless-stopped \

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= \
    --env TZ="America/Chicago" \
    --dns= \
    --dns= \
    --restart=unless-stopped \

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_DRIVER_CAPABILITIES=compute,utility,video \

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 \

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 \

3 Answers 3



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 with 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.

  • 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

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.


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

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


  • ./resolv.conf:/etc/resolv.conf
  • 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 .