2

I was trying to run below command for testing docker connectivity to INTERNET.

docker run appropriate/curl https://google.com

It doesn't work and says cannot resolve the host. Then I checked the docker0 bridge which is used in this process.

xxxx-yy$ ip route
default via 10.0.2.2 dev enp0s3  proto static  metric 100 
10.0.2.0/24 dev enp0s3  proto kernel  scope link  src 10.0.2.15  metric 100 
169.254.0.0/16 dev enp0s3  scope link  metric 1000 
172.26.0.0/16 dev docker0  proto kernel  scope link  src 172.26.0.1 linkdown

I also checked in another system where it was working fine and there was no "linkdown". Could anyone help as why in my system the docker0 status is down (linkdown). I have restarted then reinstalled the docker but with no success. I also changed the IP range from default to this new one.

The docker is running on a Ubuntu virtualbox.

E. Roid
  • 99
  • 1
  • 11
  • Try `ping 8.8.8.8` instead of curl, does that make a difference? Trying to understand if you are having NAT problem or if your DNS resolver is misconfigured. – Bjoern Rennhak Jun 06 '18 at 10:30
  • docker run appropriate/ping xxx combination is not supported by docker. – E. Roid Jun 06 '18 at 10:35
  • Try this.. `docker pull busybox` and `docker run busybox ping 8.8.8.8` does ping work? If so, then you have a misconfigured DNS resolver, if no then its a NAT issue. – Bjoern Rennhak Jun 06 '18 at 10:38
  • The ping works. But how I misconfigured DNS? I haven't changed anything after installing the docker. – E. Roid Jun 06 '18 at 10:48
  • $ 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 nameserver 127.0.1.1 – E. Roid Jun 06 '18 at 10:53
  • Does this work for you? `docker run --dns 8.8.8.8 --rm appropriate/curl -fsSL https://google.com` – Bjoern Rennhak Jun 06 '18 at 10:54
  • No. "Could not resolve the host" – E. Roid Jun 06 '18 at 10:55
  • What kind of resolver do you have in the hosts (ubuntu) `/etc/resolv.conf` ? Please add, `nameserver 8.8.8.8` there and try again. – Bjoern Rennhak Jun 06 '18 at 11:01
  • I added but still the same problem. Not able to resolve the host. – E. Roid Jun 06 '18 at 11:26
  • Does your network block DNS requests to external DNS servers? What is the IP of your internal DNS server? You should use that directly with docker. I also recommend removing dnsmasq since docker can't use the dnsmasq ip address in containers, resulting to the fallback to 8.8.8.8. – BMitch Jun 06 '18 at 13:21

1 Answers1

0

I have the same issue on an AWS Workspaces (kind of like EC2 with a desktop) and networking in docker using the default bridge network does not work. You can see in the ip output that the docker0 bridge has linkdown attribute - but that is not actually the problem: it says linkdown whenever there are no current docker containers running and attached to the docker bridge.

One workaround is to create a custom Docker network and these custom networks does not seem to have a problem, even when the default network doesn't connect. So something like:

docker network create --driver bridge --subnet 192.168.0.0/24 --gateway 192.168.0.1 test

Then when you run the container, select the custom network:

docker run -ti --rm --network test appropriate/curl https://google.com

The actual problem is very likely that the default DNS configuration for the default Docker bridge is not correct - for some reason - and you can fix the problem (not actually a fix, more like another more permanent workaround) by setting a fixed DNS server address in the Docker configuration file /etc/docker/daemon.json. See this answer for the details.

Guss
  • 30,470
  • 17
  • 104
  • 128