The issue has been resolved by myself recently. Totally, i’ve been fighting this problem on and off for almost one week, fortunately, some posts in github, stackoverflow, askubuntu, etc, gave me insights. Hope my way would be helpful to you.
Step1: Check the DNS server you’re using through typing:
mingchen@mingchen-HP:~$ nm-tool | grep DNS
In my terminal, I got；
Step2: copy the above DNS server to the '/etc/docker/daemon.json’
$ sudo gedit /etc/docker/daemon.json
just like the following format:
“dns”: [“22.214.171.124”,“172.20.1.4”,“172.20.1.6”, “127.0.0.1”,“126.96.36.199”]
Step3: restart docker service.
$ sudo service docker restart
Step4: Run a docker container and test it!
The following is my test result:
root@95ce75c5dbc0:/# ping baidu.com
PING baidu.com (188.8.131.52) 56(84) bytes of data.
64 bytes from 184.108.40.206: icmp_seq=1 ttl=51 time=38.0 ms
64 bytes from 220.127.116.11: icmp_seq=2 ttl=51 time=37.7 ms
64 bytes from 18.104.22.168: icmp_seq=3 ttl=51 time=37.8 ms
Step5; Hope my post is helpful to you.