Docker daemon and DNS

2019-07-24 03:58发布

问题:

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



标签: dns docker