Custom Bridge for Docker network configuration

Source: Internet
Author: User

Use a specific range of IP

Docker will try to find an IP segment that is not being used by the host, although it works in most cases, but it is not omnipotent, and sometimes we still need to plan for the IP further. Docker allows you to manage the Docker0 bridge or customize the bridging network card with the-B option, and you need to install the Bridge-utils package.

The basic steps are as follows:

      • Ensure Docker is stopped
        • # Make sure the Docker process is stopped
      • Create your own bridge (Bridge0 for example)
        • # Create a custom bridge
      • Assign a specific IP to this bridge
        • # Assign a specific IP to the bridge
      • Start Docker with THE-B=BRIDGE0 parameter
        • # Specify the Network bridge in-B mode

In addition to the default Docker0 bridge, users can also specify a bridge to connect to each container.
When you start 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 10.0.200.1/24 dev bridge0
$ sudo ip link set dev bridge0 up
View The Network Bridge is created and started.
$ IP Addr Show bridge0
4:bridge0: <BROADCAST,MULTICAST> MTU Qdisc noop State up group default
link/e Ther 66:38:d0:0d:76:18 brd ff:ff:ff:ff:ff:ff
inet 10.0.200.1/24 scope global BRIDGE0
Valid_lft Forever Preferred_ LFT Forever
Configures the Docker service, which is the default bridge to the created bridge.
$vim/etc/sysconfig/docker

Other_args= '--insecure-registry 10.0.30.5:5000--graph=/data/docker/images -b=bridge0'
$ sudo service docker start
Start the Docker service. Create a new container and see that it has been bridged to the BRIDGE0.
You can continue to view bridged information with the BRCTL Show command. In addition, the IP addr and IP route commands can be used in containers to
View IP address configuration and routing information.

5. The external host needs to add a static receipt route when it wants to access the in-container IP

Route add-net 10.0.200.0 netmask 255.255.255.0 GW 10.0.30.6( the host IP where the container resides)

Custom Bridge for Docker network configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.