Installing docker-ce in Ubuntu 18.04 breaks internet connectivity of host

Solution 1:

So here's your problem:

Docker has assigned the range 172.17.0.1/16 to your docker0 interface. This includes all addresses from 172.17.0.1 through 172.17.255.255. You will note that this range includes your DNS servers (172.17.100.3 and 172.17.100.70). What you have is a routing problem:

Whenever you host needs to reach your DNS servers, it sees that it has an interface already on the same network (docker0), so it tries to route packets using that interface...which of course go nowhere, which is why your DNS stops working.

Docker doesn't have a simple mechanism for excluding an address range from it's automatic selection process, so you'll probably need to do two things to resolve the problem:

First, explicitly set the address of docker0 in your /etc/docker/daemon.json. Use any network that doesn't conflict your internal networks. E.g.:

{
  "bip": "172.31.0.1/16"
}

You'll need to restart Docker.

Next, to prevent Docker from selecting the same network range for a user defined network (one that you create explicitly using docker network create or implicitly using, e.g., docker-compose or docker stack ...), create a new network and then never use it:

docker network create --subnet 172.17.0.0/16 --config-only do_not_use

This should both resolve your problem and prevent it from cropping back up in the future.

Update

Docker actually documents an arguably better way of accomplishing this in How do I influence which network address ranges Docker chooses during a 'docker network create'?.

This requires setting persistent static routes on your system, which varies between Linux distributions.