Gangmax Blog

自由之思想,独立之精神

How to Configure Docker Default Bridge Docker0

| Comments

From here and here.

I got the problem that I found I could not ping the IP address “172.17.54.104” within my Linux VM. The IP address is an internal server. Then I found the root cause is that, Docker is installed on my Linux VM which by default create a “docker0” bridge with the IP range “172.17.x.x”. So an IP routing rule is created for the “172.17.x.x” IP range which overrides the corrrect IP I want to access.

A workaround is to execute the following command to remove the IP routing rule:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
~> ip route
default via 10.0.2.2 dev enp0s3  proto static  metric 100
10.0.2.0/24 dev enp0s3  proto kernel  scope link  src 10.0.2.15  metric 100
169.254.0.0/16 dev enp0s3  scope link  metric 1000
172.17.0.0/16 dev docker0  proto kernel  scope link  src 172.17.0.1 linkdown
172.18.0.0/16 dev br-13577d02e3c9  proto kernel  scope link  src 172.18.0.1 linkdown
172.19.0.0/16 dev br-b4dd75363d88  proto kernel  scope link  src 172.19.0.1 linkdown
~> sudo ip route delete 172.17.0.0/16
~> ip route
default via 10.0.2.2 dev enp0s3  proto static  metric 100
10.0.2.0/24 dev enp0s3  proto kernel  scope link  src 10.0.2.15  metric 100
169.254.0.0/16 dev enp0s3  scope link  metric 1000
172.18.0.0/16 dev br-13577d02e3c9  proto kernel  scope link  src 172.18.0.1 linkdown
172.19.0.0/16 dev br-b4dd75363d88  proto kernel  scope link  src 172.19.0.1 linkdown

However, in this case if you restart the OS, the routing rule will come back. The final solution is that, update(or create if it’s not existing) the “/etc/docker/daemon.json” file like below:

/etc/docker/daemon.json
1
2
3
4
{
  "bip": "172.26.0.1/16",
  ... // Other content if there is.
}

Then restart the Docker service:

1
sudo service docker restart

Now if you execute the “ifconfig” command, you can see the “docker0” network’s IP address is updated to “inet addr:172.26.0.1”. And it will still work after OS restarts.

Comments