Created
June 20, 2017 14:22
-
-
Save roipoussiere/4600d2ff62e3bb321a7c58b2d26df504 to your computer and use it in GitHub Desktop.
Having troubles with Docker DNS?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# First, verify that your Docker DNS are actually incorrecly configured | |
# by dowloading the Debian image, creating a container and ping the Debian archives repository from it. | |
# $ docker run -it debian ping 128.31.0.62 # the IP of the repository | |
# This should work: | |
# > [...] 2 packets transmitted, 2 packets received, 0% packet loss | |
# If not, this is not a DNS issue. | |
# $ docker run -it debian ping deb.debian.org # the URL of the repository | |
# If you get this message: | |
# > ping: unknown host | |
# you may have a DNS issue and must execute this script. | |
# 1. Get your DNS | |
dns=($(nmcli device show $(ip route list | awk '/^default/ {print $5}') | grep DNS | sed -E "s/.*:\s+//g")) | |
# 2. Set configure Docker DNS (the way to do it depends if your init system is systemd or not) | |
if ps -o comm -1 | grep -q systemd; then | |
cat /lib/systemd/system/docker.service | sed '/^ExecStart.*/ s/$/ --dns='"${dns[1]}"' --dns='"${dns[2]}"'/' > /tmp/docker.service | |
sudo mv /tmp/docker.service /lib/systemd/system/docker.service | |
elif | |
sudo bash -c "echo 'DOCKER_OPTS=\"--dns '${dns[1]}' --dns '${dns[2]}'\"' >> /etc/default/docker" | |
fi | |
# Now check again! | |
# $ docker run -it debian ping deb.debian.org | |
# > [...] 2 packets transmitted, 2 packets received, 0% packet loss | |
# Hurrah! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment