DNS does not work in docker. Docker can reach DNS provider and has correct IP. Host works

I have Docker installed on Ubuntu Server 22.04 (via apt not snap). Everything was working until I upgraded from 20.04 to 22.04. Now, DNS does not work inside docker.

$ sudo docker run busybox nslookup google.com
Server:         1.1.1.1
Address:        1.1.1.1:53

Non-authoritative answer:
Name:   google.com
Address: 172.217.0.78

*** Can't find google.com: No answer

as you can see, docker is attempting to use 1.1.1.1 to resolve the domain but cannot reach it. If we do the same thing on the host

$ nslookup google.com
Server:         1.1.1.1
Address:        1.1.1.1#53

Non-authoritative answer:
Name:   google.com
Address: 172.217.0.78
Name:   google.com
Address: 2607:f8b0:4025:815::200e

everything works as expected.

Docker can for sure reach the DNS server because we can ping it

$ sudo docker run busybox ping 1.1.1.1
PING 1.1.1.1 (1.1.1.1): 56 data bytes
64 bytes from 1.1.1.1: seq=0 ttl=56 time=13.370 ms
64 bytes from 1.1.1.1: seq=1 ttl=56 time=15.364 ms
64 bytes from 1.1.1.1: seq=2 ttl=56 time=11.075 ms
64 bytes from 1.1.1.1: seq=3 ttl=56 time=10.229 ms
64 bytes from 1.1.1.1: seq=4 ttl=56 time=11.113 ms
64 bytes from 1.1.1.1: seq=5 ttl=56 time=17.715 ms
^C
--- 1.1.1.1 ping statistics ---
6 packets transmitted, 6 packets received, 0% packet loss
round-trip min/avg/max = 10.229/13.144/17.715 ms

resolv.conf is pretty typical

$ cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
# 127.0.0.53 is the systemd-resolved stub resolver.
# run "systemd-resolve --status" to see details about the actual nameservers.
nameserver 1.1.1.1
nameserver 127.0.0.1
nameserver 172.17.0.1
1 Like

Did you upgrade Ubuntu with Docker installed on it, or you installed Docker on after you upgraded Ubuntu? I have run Docker containers on ubuntu 18.04, 20.04 and 22.04. When I upgraded from 18.04 to 20.04 I already had Docker, but it worked after the upgrading. Docker on my Ubuntu 22.04 server was a clean install after installing the operating system and that worked well too, but it is possible that something went wrong when you upgraded Ubuntu from 20.04 to 22.04. Have you tried to reinstall Docker?