Docker On DigitalOcean Cannot Resolve Hostnames

Overview

I encountered an issue where during the build of my Docker container it was not able to get a response back during an apt-get update command. It turns out it was unable to resolve the DNS entries because of the IPV6 entries in /etc/resolv.conf

The Fix

Edit /etc/resolv.conf and comment out the first 2 lines by adding a ‘#’ at the beginning line. For example in my case it was:

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND — YOUR CHANGES WILL BE OVERWRITTEN
nameserver 2001:4860:4860::8844
nameserver 2001:4860:4860::8888
nameserver 209.244.0.3

to

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND — YOUR CHANGES WILL BE OVERWRITTEN
#nameserver 2001:4860:4860::8844
#nameserver 2001:4860:4860::8888
nameserver 209.244.0.3

Docker DNS

Another thing to note is to set the DNS which Docker should use. It can be done on docker run but to save time you can set it globally in /etc/default/docker

There is a line:
#DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4"
Remove the ‘#’ at the beginning of the line and it will use Google’s DNS servers. The IP address can be changed to your preferred DNS provider.

Summary

A simple but hair tearing moment when you encounter these configuration issues. The IPv6 issue seems even more odd and begs the question why enable it at all on Digital Ocean.

About Danny

I.T software professional always studying and applying the knowledge gained and one way of doing this is to blog. Danny also has participates in a part time project called Energy@Home [http://code.google.com/p/energyathome/] for monitoring energy usage on a premise. Dedicated to I.T since studying pure Information Technology since the age of 16, Danny Tsang working in the field that he has aimed for since leaving school. View all posts by Danny → This entry was posted in Linux and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *.

All comments must go through an approval and anti-spam process before appearing on the website. Please be patience and do not re-submit your comment if it does not appear.

This site uses Akismet to reduce spam. Learn how your comment data is processed.