Created
May 25, 2019 12:15
-
-
Save IslamAlam/0c9e9dc42126d60cfed66f4779fd8047 to your computer and use it in GitHub Desktop.
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
**1\. Hardcode DNS server in docker daemon.json** | |
* Edit `/etc/docker/daemon.json` | |
{ | |
"dns": ["10.1.2.3", "8.8.8.8"] | |
} | |
* Restart the docker daemon for those changes to take effect: | |
`sudo systemctl restart docker` | |
* Now when you run/start a container, docker will populate `/etc/resolv.conf` with the values from `daemon.json`. | |
* * * | |
**2\. Fix the hosts's `/etc/resolv.conf`** | |
**A. Ubuntu 16.04 and earlier** | |
* For Ubuntu 16.04 and earlier, `/etc/resolv.conf` was dynamically generated by NetworkManager. | |
* Comment out the line `dns=dnsmasq` (with a `#`) in `/etc/NetworkManager/NetworkManager.conf` | |
* Restart the NetworkManager to regenerate `/etc/resolv.conf` : | |
`sudo systemctl restart network-manager` | |
* Verify on the host: `cat /etc/resolv.conf` | |
**B. Ubuntu 18.04 and later** | |
* Ubuntu 18.04 changed to use [`systemd-resolved` to generate `/etc/resolv.conf`](http://manpages.ubuntu.com/manpages/bionic/man8/systemd-resolved.service.8.html#contenttoc3). Now by default it uses a local DNS cache 127.0.0.53\. That will not work inside a container, so Docker will default to Google's 8.8.8.8 DNS server, which may break for people behind a firewall. | |
* `/etc/resolv.conf` is actually a symlink (`ls -l /etc/resolv.conf`) which points to `/run/systemd/resolve/stub-resolv.conf` (127.0.0.53) by default in Ubuntu 18.04. | |
* Just change the symlink to point to `/run/systemd/resolve/resolv.conf`, which lists the real DNS servers: | |
`sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf` | |
* Verify on the host: `cat /etc/resolv.conf` | |
Now you should have a valid `/etc/resolv.conf` on the host for docker to copy into the containers. | |
## Install Docker | |
' | |
sudo apt-get install bridge-utils | |
sudo pkill docker | |
sudo iptables -t nat -F | |
sudo ifconfig docker0 down | |
sudo brctl delbr docker0 | |
sudo service docker restart | |
' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
1. Hardcode DNS server in docker daemon.json
Edit
/etc/docker/daemon.json
Restart the docker daemon for those changes to take effect:
sudo systemctl restart docker
Now when you run/start a container, docker will populate
/etc/resolv.conf
with the values fromdaemon.json
.2. Fix the hosts's
/etc/resolv.conf
A. Ubuntu 16.04 and earlier
For Ubuntu 16.04 and earlier,
/etc/resolv.conf
was dynamically generated by NetworkManager.Comment out the line
dns=dnsmasq
(with a#
) in/etc/NetworkManager/NetworkManager.conf
Restart the NetworkManager to regenerate
/etc/resolv.conf
:sudo systemctl restart network-manager
Verify on the host:
cat /etc/resolv.conf
B. Ubuntu 18.04 and later
Ubuntu 18.04 changed to use
systemd-resolved
to generate/etc/resolv.conf
. Now by default it uses a local DNS cache 127.0.0.53. That will not work inside a container, so Docker will default to Google's 8.8.8.8 DNS server, which may break for people behind a firewall./etc/resolv.conf
is actually a symlink (ls -l /etc/resolv.conf
) which points to/run/systemd/resolve/stub-resolv.conf
(127.0.0.53) by default in Ubuntu 18.04.Just change the symlink to point to
/run/systemd/resolve/resolv.conf
, which lists the real DNS servers:sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf
Verify on the host:
cat /etc/resolv.conf
Now you should have a valid
/etc/resolv.conf
on the host for docker to copy into the containers.Install Docker
https://docs.docker.com/install/linux/docker-ce/ubuntu/
Manage Docker as a non-root user
Create the
docker
group.Add your user to the
docker
group.Log out and log back in so that your group membership is re-evaluated.
If testing on a virtual machine, it may be necessary to restart the virtual machine for changes to take effect.
On a desktop Linux environment such as X Windows, log out of your session completely and then log back in.
Verify that you can run
docker
commands withoutsudo
.This command download
Docker containers can't resolve DNS on Ubuntu 14.04 Desktop Host
Woo, I found a post on github that solved my problem.
After Steve K. pointed out that it wasn't actually a DNS issue and was a connectivity issue, I was able to find a post on github that described how to fix this problem.
Apparently the docker0 network bridge was hung up. Installing bridge-utils and running the following got my Docker in working order: