Skip to content

Instantly share code, notes, and snippets.

@IslamAlam
Created May 25, 2019 12:15
Show Gist options
  • Save IslamAlam/0c9e9dc42126d60cfed66f4779fd8047 to your computer and use it in GitHub Desktop.
Save IslamAlam/0c9e9dc42126d60cfed66f4779fd8047 to your computer and use it in GitHub Desktop.
**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
'
@IslamAlam
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment