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
Best Answer
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 the127.0.0.1
with10.0.10.1
to see if/etc/resolv.conf
would change. I rebooted and it indeed changed. I removeddhcpcd
withapt 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.