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

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

问题描述

我在我的 Mac 上运行 boot2docker.OSX 版本 10.9.3boot2docker 版本 4.3.12Docker 版本 0.12.0

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

boot2docker 镜像是一个 vagrant box,使用的是 virtualbox.我尝试了许多流浪盒子(例如 stigkj/boot2docker).他们都表现出这个问题.

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.

如果我通过 ssh 进入 boot2docker 映像并查看/etc/resolv.conf,它正在使用名称服务器 10.0.2.3.

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

我使用以下命令启动了一个简单的 docker 镜像:

I boot up a simple docker image with the command:

docker run -i -t ubuntu /bin/sh

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

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

在boot2docker vm上的docker.log文件中,有这么一行:

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]

据我了解,docker 应该使用主机的名称服务器.仅当主机使用 127.0.0.1 作为其名称服务器时,才应默认使用 google 名称服务器作为备份.

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.

主机没有使用 127.0.0.1 作为名称服务器,但似乎 docker 认为它是.关于如何让它正确检测名称服务器的任何建议?

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?

推荐答案

我找到了解决方法.看起来 boot2docker 镜像在从主机拉取 DNS 之前运行了 docker 守护进程.所以boot2docker在启动时认为DNS设置为127.0.0.1,然后机器将其更改为正确的名称服务器.

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.

修复方法是在映像启动后重新启动 docker 守护进程.在 vagrant 中,我通过在 Vagrantfile 的适当位置添加以下命令来做到这一点:

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"

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

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天全站免登陆