Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker daemon and DNS

Tags:

docker

dns

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 ?

like image 481
Florent Valdelievre Avatar asked Sep 13 '26 06:09

Florent Valdelievre


1 Answers

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

like image 178
Vitaly Isaev Avatar answered Sep 16 '26 06:09

Vitaly Isaev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!