# Close docker first
$ sudo service docker stop
# Close the bridge docker0# Add your own bridge bridge0
$ sudo ifconfig docker0 down
$ sudo brctl addbr bridge0
$ sudo ifconfig bridge0 192.168.227.1 netmask 255.255.255.0
# Add startup custom bridge parameters to Docker startup file
$ echo "DOCKER_OPTS=\"-b=bridge0\"" >> /etc/default/docker
# 启动Docker
$ sudo service docker start
# Check whether the custom bridge is successfully started and whether the ip and other configurations are correct.
$ sudo ifconfig bridge0
bridge0 Link encap:Ethernet HWaddr xx:xx:xx:xx:xx:xx
inet addr:192.168.227.1 Bcast:192.168.227.255 Mask:255.255 .255.0
# 启动container
docker run -i -t base /bin/bash
# You can see that the Container IP is in the network segment 192.168.227/24
root@261c272cd7d5:/ # ifconfig eth0
eth0 Link encap:Ethernet HWaddr xx:xx:xx:xx:xx:xx
inet addr:192.168.227.5 Bcast:192.168. 227.255 Mask: 255.255.255.0
# bridge0 IP as the default gateway# View routing information
root@261c272cd7d5:/ # route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.227.1 0.0.0.0 UG 0 0 0 eth0
192.168.227.0 0.0 .0.0 255.255.255.0 U 0 0 0 eth0
# hits CTRL+P then CTRL+Q to detach
# View bridge information
$ sudo brctl show
bridge name bridge id STP enabled interfaces
bridge0 8000.fe7c2e0faebd no vethAQI2QT