Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker containers not using host DNS in boot2docker

I am running boot2docker on my Mac. OSX version 10.9.3 boot2docker version 4.3.12 Docker version 0.12.0

The boot2docker image is a vagrant box, using virtualbox. I have tried a number of vagrant boxes (for example stigkj/boot2docker). All of them exhibiting the issue.

If I ssh into the boot2docker image and look at /etc/resolv.conf it is using the nameserver 10.0.2.3.

I boot up a simple docker image with the command:

docker run -i -t ubuntu /bin/sh

Looking at /etc/resolv.conf in that container, it is using 8.8.8.8 and 8.8.4.4 as nameservers.

In the docker.log file on the boot2docker vm, there is this line:

2014/06/30 15:25:01 Local (127.0.0.1) DNS resolver found in resolv.conf and containers can't use it. Using default external servers : [8.8.8.8 8.8.4.4]

From what I understand, docker is supposed to use the nameserver of the host. Only if the host is using 127.0.0.1 as it's nameserver should it default to the google nameservers as a backup.

The host isn't using 127.0.0.1 as a name server, but it appears that docker thinks it is. Any suggestions on how I can get it to properly detect the nameserver?

like image 983
oillio Avatar asked Jun 30 '14 15:06

oillio


People also ask

Do Docker containers use host DNS?

DNS services conf configuration file. Containers that use the default bridge network get a copy of this file, whereas containers that use a custom network use Docker's embedded DNS server, which forwards external DNS lookups to the DNS servers configured on the host.

How do I fix my Docker DNS?

Permanent fix for docker image DNS lookup error First, we will change the DNS settings of the Docker daemon by creating the daemon configuration file at /etc/docker/daemon. json. Then, configure the daemon configuration file with a set of two DNS, namely, the network DNS server and the Google DNS server.

What DNS does a Docker container use?

Docker containers take DNS IPs from the host machine, which is managed by systemd-resolve . Those IPs themselves are the cloud provider's DNS.


Video Answer


2 Answers

I found a fix. It appears that the boot2docker image runs the docker daemon before it pulls the DNS from the host. So boot2docker thinks the DNS is set to 127.0.0.1 when it boots, then the machine changes it to the correct nameserver.

The fix is to restart the docker daemon after the image has booted. In vagrant, I did this by adding the below command in the appropriate place in my Vagrantfile:

config.vm.provision :shell, inline: "/etc/init.d/docker restart"

It looks like this is a known issue in boot2docker that will be fixed in an upcoming version: https://github.com/boot2docker/boot2docker/issues/357

like image 103
oillio Avatar answered Oct 11 '22 17:10

oillio


credit to @oillio for the issue link and the discussion inside.

It happens in Windows 7 environment as well using boot2docker 1.0.1, I follow the suggestion in https://github.com/boot2docker/boot2docker/issues/357

$ sudo udhcpc   # refresh the DHCP 
$ sudo /etc/init.d/docker restart # restart the service
like image 2
Larry Cai Avatar answered Oct 11 '22 17:10

Larry Cai