28.Docker custom bridge

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

Docker start the service, use -b BRIDGEor --bridge=BRIDGEto specify the use of the bridge.

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

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

Then create a network 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 to confirm 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 bridge to the created bridge by default.

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

Start the Docker service. Create a new container, you can see that it has received a bridge bridge0on.

You can continue to brctl showview the information bridge of command. Further, the container may be used ip addrand the ip routecommand to view the IP address configuration and routing information.

Guess you like

Origin blog.csdn.net/shujuelin/article/details/108375354