How to configure DNS proxy for docker containers

Posted By : Shiv Pujan Maurya | 18-Dec-2017

DNS servers play out the administration of settling a space name with an IP address and the other way around. When you arrange the firewall as a DNS intermediary, it goes about as a mediator amongst IPs and servers and as a DNS server by settling questions from its DNS reserve or sending inquiries to different DNS servers. 

While assessing a container with  hostname from localhost we face an issue that they cannot be called from host machine via their name. This issue can be resolved by implementing a local dns proxy server. This proxy server can run in container itself.

 

How does this configuration works

 

1. DNS first calls local hosts container

2. Then from local dns database

3. Last from remote DNS server.

 

For installing dns proxy with docker we are using an opensource dns repository (mageddo proxy server)

 

 docker run --hostname dns.test --name dns-test-proxy-server -p 5380:5380 -v /opt/dns-proxy-server/conf:/app/conf -v /var/run/docker.sock:/var/run/docker.sock -v /etc/resolv.conf:/etc/resolv.conf defreitas/dns-proxy-server

 

Now  we need to start some containers for testing dns

 

docker run -d --hostname debian.dev.intranet -e 'HOSTNAMES=debian2.dev.intranet,debian3.dev.intranet' debian sleep infinity

 

 

Lets check the web console for manual entries 

 

 

Now lets set dns proxy as default proxy

sudo echo 'nameserver <192.168.43.164>' > /etc/resolv.conf

Lets run new cenos container

"sudo docker run centos"

 

Now check both containers

"sudo docker ps"

 

 

Connect to centos container and get hostname

 

"sudo docker exec -it <container id> /bin/bash"

 

 

 

Now ping centos from local host

 

ping  <container host name>

 

 
Done
 
Thank You

About Author

Author Image
Shiv Pujan Maurya

Shiv is a Redhat certified engineer with B.Tech in Computer Science & Engineering. He is passionate about new technologies specially in DevOps and Artificial intelligence.

Request for Proposal

Name is required

Comment is required

Sending message..