github.com/brahmaroutu/docker@v1.2.1-0.20160809185609-eb28dde01f16/docs/userguide/networking/default_network/build-bridges.md (about)

     1  <!--[metadata]>
     2  +++
     3  title = "Build your own bridge"
     4  description = "Learn how to build your own bridge interface"
     5  keywords = ["docker, bridge, docker0, network"]
     6  [menu.main]
     7  parent = "smn_networking_def"
     8  +++
     9  <![end-metadata]-->
    10  
    11  # Build your own bridge
    12  
    13  This section explains how to build your own bridge to replace the Docker default
    14  bridge. This is a `bridge` network named `bridge` created automatically when you
    15  install Docker.
    16  
    17  > **Note**: The [Docker networks feature](../dockernetworks.md) allows you to
    18  create user-defined networks in addition to the default bridge network.
    19  
    20  You can set up your own bridge before starting Docker and use `-b BRIDGE` or
    21  `--bridge=BRIDGE` to tell Docker to use your bridge instead. If you already
    22  have Docker up and running with its default `docker0` still configured,
    23  you can directly create your bridge and restart Docker with it or want to begin by
    24  stopping the service and removing the interface:
    25  
    26  ```
    27  # Stopping Docker and removing docker0
    28  
    29  $ sudo service docker stop
    30  
    31  $ sudo ip link set dev docker0 down
    32  
    33  $ sudo brctl delbr docker0
    34  
    35  $ sudo iptables -t nat -F POSTROUTING
    36  ```
    37  
    38  Then, before starting the Docker service, create your own bridge and give it
    39  whatever configuration you want. Here we will create a simple enough bridge
    40  that we really could just have used the options in the previous section to
    41  customize `docker0`, but it will be enough to illustrate the technique.
    42  
    43  ```
    44  # Create our own bridge
    45  
    46  $ sudo brctl addbr bridge0
    47  
    48  $ sudo ip addr add 192.168.5.1/24 dev bridge0
    49  
    50  $ sudo ip link set dev bridge0 up
    51  
    52  # Confirming that our bridge is up and running
    53  
    54  $ ip addr show bridge0
    55  
    56  4: bridge0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state UP group default
    57      link/ether 66:38:d0:0d:76:18 brd ff:ff:ff:ff:ff:ff
    58      inet 192.168.5.1/24 scope global bridge0
    59         valid_lft forever preferred_lft forever
    60  
    61  # Tell Docker about it and restart (on Ubuntu)
    62  
    63  $ echo 'DOCKER_OPTS="-b=bridge0"' >> /etc/default/docker
    64  
    65  $ sudo service docker start
    66  
    67  # Confirming new outgoing NAT masquerade is set up
    68  
    69  $ sudo iptables -t nat -L -n
    70  
    71  ...
    72  Chain POSTROUTING (policy ACCEPT)
    73  target     prot opt source               destination
    74  MASQUERADE  all  --  192.168.5.0/24      0.0.0.0/0
    75  ```
    76  
    77  The result should be that the Docker server starts successfully and is now
    78  prepared to bind containers to the new bridge. After pausing to verify the
    79  bridge's configuration, try creating a container -- you will see that its IP
    80  address is in your new IP address range, which Docker will have auto-detected.
    81  
    82  You can use the `brctl show` command to see Docker add and remove interfaces
    83  from the bridge as you start and stop containers, and can run `ip addr` and `ip
    84  route` inside a container to see that it has been given an address in the
    85  bridge's IP address range and has been told to use the Docker host's IP address
    86  on the bridge as its default gateway to the rest of the Internet.