Docker容器在boot2docker中不使用主机DNS [英] Docker containers not using host DNS in boot2docker

查看:207
本文介绍了Docker容器在boot2docker中不使用主机DNS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Mac上运行boot2docker。
OSX版本10.9.3
boot2docker版本4.3.12
Docker版本0.12.0



boot2docker图像是一个流氓框,使用virtualbox。我试过了一些流氓盒子(例如stigkj / boot2docker)。所有这些都表现出这个问题。



如果我进入boot2docker镜像并查看/etc/resolv.conf,它使用的是名称服务器10.0.2.3。 >

我使用命令启动一个简单的docker图像:

  docker run  - i -t ubuntu / bin / sh 

查看该容器中的/etc/resolv.conf正在使用8.8.8.8和8.8.4.4作为名称服务器。



在boot2docker vm的 docker.log 文件有这条线:

  2014/06/30 15:25:01本地(127.0.0.1)DNS解析器resolv.conf和容器不能使用它。使用默认的外部服务器:[8.8.8.8 8.8.4.4] 

根据我的理解,使用主机的名称服务器。只有当主机正在使用127.0.0.1作为它的名称服务器时,应该默认将google名称服务器作为备份。



主机不使用127.0.0.1作为名称服务器,但看来docker认为是。任何有关如何使其正确检测名称服务器的建议?

解决方案

我发现了一个修复。
看起来,boot2docker镜像在从主机提取DNS之前运行docker守护程序。因此,boot2docker认为启动时DNS设置为127.0.0.1,然后机器将其更改为正确的名称服务器。



修复程序是在重新启动docker守护程序后图像已启动。
在流氓中,我通过在我的Vagrantfile中的适当位置添加以下命令:

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

看起来像这是boot2docker中的一个已知问题,将在即将发布的版本中修复:
https:/ /github.com/boot2docker/boot2docker/issues/357


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?

解决方案

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

这篇关于Docker容器在boot2docker中不使用主机DNS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆