May 22, 2021 Docker From entry to practice
In addition to the
docker0
bridge, users can also specify bridges to connect individual containers.
When you start the Docker service, use
-b BRIDGE
--bridge=BRIDGE
specify the bridge to use.
If the service is already running, you need to stop the service first and remove 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 to confirm that the bridge was 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, which is bridged by default to the created bridge.
$ echo 'DOCKER_OPTS="-b=bridge0"' >> /etc/default/docker
$ sudo service docker start
Start the Docker service.
Create a new container and you can see that it has been
bridge0
You can continue to view the bridged information with the
brctl show
command.
In addition, ip addr and
ip addr
can be
ip route
in containers to view IP address configuration and routing information.