Modify docker to start default bridge docker0 for custom Bridges

  • 2020-06-15 10:31:54
  • OfStack

Custom bridge

In addition to the default docker0 bridge, the user can also specify a bridge to connect the containers.

When starting the Docker service, use -b BRIDGE or --bridge=BRIDGE to specify the bridge to use.

If the service is already running, you need to stop the service and delete the old bridge.


$ sudo service docker stop
$ sudo ip link set dev docker0 down
$ sudo brctl delbr docker0

Then create a bridge, bridge0.


$ sudo brctl addbr bridge0
$ sudo ip addr add 192.168.5.1/24 dev bridge0
$ sudo ip link set dev bridge0 up

Check that the bridge is created and started.


$ ip addr show bridge0
4: bridge0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state UP group default
  link/ether 66:38:d0:0d:76:18 brd ff:ff:ff:ff:ff:ff
  inet 192.168.5.1/24 scope global bridge0
    valid_lft forever preferred_lft forever

Configure the Docker service to connect the default bridge to the created bridge.


$ echo 'DOCKER_OPTS="-b=bridge0"' >> /etc/default/docker
$ sudo service docker start

Start Docker service. Create a new container and see that it is bridged to bridge0.

You can continue to view the bridge information with the brctl show command. In addition, the ip addr and ip route commands can be used in the container to view the IP address configuration and routing information.


Related articles: