Docker守护进程和DNS [英] Docker daemon and DNS

查看:183
本文介绍了Docker守护进程和DNS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图强制docker守护进程使用绑定到bridge0接口的DNS服务器。
我已经在docker_opts中添加了--dns 172.17.42.1,但没有成功。

I am trying to force the docker daemon to use my DNS server which is binded to bridge0 interface. I have added --dns 172.17.42.1 in my docker_opts but no success

DNS服务器回复ok with dig命令:

DNS server reply ok with dig command:

dig @172.17.42.1 registry.service.consul SRV +short
1 1 5000 registry2.node.staging.consul.

但是,该域失败:

docker pull registry.service.consul:5000/test
FATA[0000] Error: issecure: could not resolve "registry.service.consul": lookup registry.service.consul: no such host

PS:通过在我的/etc/resolv.conf解决方案中添加nameserver 172.17.42.1这个问题,但DNS必须是专门用于docker命令。

PS: By adding nameserver 172.17.42.1 in my /etc/resolv.conf solve the issue but the DNS has to be exclusively for docker commands.

任何想法?

推荐答案

您将 - dns 172.17.42.1 传递到docker_opts,因此您应该能够从其他容器内部解析容器主机名。 显然,您正在从主机进行 docker pull ,而不是从容器,不是吗?因此,您无法从主机中解析容器的主机名并不奇怪,因为它未配置为使用 172.17.42.1 进行解析。

You passed --dns 172.17.42.1 to docker_opts, so since that you should be able to resolve the container hostnames from inside other containers. But obviously you're doing docker pull from the host, not from the container, isn't it? Therefore it's not surprising that you cannot resolve container's hostname from your host, because it is not configured to use 172.17.42.1 for resolving.

我在这里看到两种可能的解决方案:

I see two possible solutions here:


  1. 强制您的主机使用 172.17.42.1 作为DNS( /etc/resolv.conf 等)。

  2. 使用Docker创建一个特殊容器客户端内部并挂载 docker.sock 。这将使您能够使用所有客户端命令,包括 pull

  1. Force your host to use 172.17.42.1 as DNS (/etc/resolv.conf etc).
  2. Create a special container with Docker client inside and mount docker.sock inside it. This will make you able to use all client commands including pull:

docker run - d -v /var/run/docker.sock:/var/run/docker.sock:rw --name = client ...

docker exec -it client docker pull registry.service.consul:5000 / test

这篇关于Docker守护进程和DNS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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