Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Configure the docker0 bridge


May 22, 2021 Docker From entry to practice



By default, the docker0 bridge docker0 internal interface that connects other physical or virtual network cards in the kernel layer, putting all containers and local hosts on the same physical network.

Docker specifies by docker0 interface, allowing the host and container to communicate with each other over a bridge, and it also gives the MTU (the maximum transmission unit allowed to be received by the interface), usually 1500 Bytes, or the default value supported on the host network route. These values can be configured when the service starts.

  • --bip=CIDR address plus mask format, e.g. 192.168.1.5/24
  • --mtu=BYTES -- overrides the default Docker mtu configuration

You can also configure the DOCKER_OPTS profile and restart the service. Because the Docker bridge is currently a Linux bridge, brctl show to view bridge and port connection information.

$ sudo brctl show
bridge name     bridge id               STP enabled     interfaces
docker0         8000.3a1d7362b4ee       no              veth65f9
                                             vethdda6

Note: brctl can be installed in Debian, Ubuntu sudo apt-get install bridge-utils

Each time a new container is created, Docker selects an idle IP address from the available address segment assigned to the container's eth0 port. Use the IP of the docker0 on the local host as the default gateway for all containers.

$ sudo docker run -i -t --rm base /bin/bash
$ ip addr show eth0
24: eth0: <BROADCAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 32:6f:e0:35:57:91 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.3/16 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::306f:e0ff:fe35:5791/64 scope link
       valid_lft forever preferred_lft forever
$ ip route
default via 172.17.42.1 dev eth0
172.17.0.0/16 dev eth0  proto kernel  scope link  src 172.17.0.3
$ exit