Docker daemon and DNS

雨燕双飞 提交于 2019-12-24 04:13:49

问题


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 server reply ok with dig command:

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

But pull with this domain fails:

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: 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.

Any idea ?


回答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. 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



来源:https://stackoverflow.com/questions/29607761/docker-daemon-and-dns

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!