Centos 7.9 , Docker version 26.1.4
Summarize:
The embedded dns server not use the new dns for the old container when the host machine dns has changed successfully, but it work for new creating contianer.
Detail:
I created my network “www”, it is bridge network, just be configed the “Subnet”: “172.88.0.0/24” and “Gateway”: “172.88.0.1”.
Then I simple create a container A1 with the config --network=www
and specify an IPV4 which in the www subnet such as 172.88.0.12. The nameserver
in the /etc/resolv.conf
in the container A1 only have one line and it is nameserver 172.0.0.11
.
I know this is the docker embedded dns, and now the network everything is normal OK, such as I try the nslookup www.google.com
and get the same result as I try in Host Machine. Now the Host Machine dns(nameserver
in /etc/resolv.conf
in Host Machine ) is 192.168.22.1.
And then, I change the Host Machine network environment(such as I take my notebook from company to home), the Host Machine dns will change to 192.168.1.1. The nslookup www.google.com
is OK in the Host Machine but not OK in container A1 (the container A1 and the dockerd service no restart).
I try to analyze the promble. I run the nslookup www.google.com
in container A1 and I use tcpdump watch the container A1 net by nsenter --net={container_A1_nets_link} tcpdump -i any -nn
in the Host Machine, I see that
IP 127.0.0.1.54976 > 127.0.0.11.52502: UDP, length 31
IP 127.0.0.1.54976 > 127.0.0.11.52502: UDP, length 31
IP 172.88.0.2.36647 > 192.168.22.1.53: 22594+ A? www.google.com. (31)
IP 172.88.0.2.38885 > 192.168.22.1.53: 22893+ AAAA? www.google.com. (31)
......
Obviously, it is still using the old dns address
192.168.22.1
now ! It sholud be the new DNS192.168.1.1
.
At this moment I try these:
ping 192.168.1.1
in container A1, it is OK;ping 192.168.22.1
in container A1, it is not OK;nslookup www.google.com 192.168.1.1
in container A1, it is OK;
And then, I simple create a container B1 as same as container A1 with another subnet IPV4 in the www network, and do the same analyze.
The container B1 work normal OK everything. The nslookup and the ping command is OK, the tcpdump show using the new DNS 192.168.1.1
.
So how let the container A1 work OK? I found it will work normal OK everything after I restart it !
Doubt:
In this using cases, why the embedded dns server 127.0.0.11
not use the new DNS? Is the embedded dns server in the every container so that it must be “refresh” the new DNS by restart container or cretea the new one?
I don’t want to restart my all conainer in each network environment change. The calude suggest me to set a myselft dns server to replace the embedded dns server, maybe it will work out but it mean I should give up using the embedded dns server, but something I need it such as I connet with container name in the network www subnet.
So it is the embedded dns server design bug and should be fixed?