github.com/boynux/docker@v1.11.0-rc4/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  $ sudo ip link set dev docker0 down
    31  $ sudo brctl delbr docker0
    32  $ sudo iptables -t nat -F POSTROUTING
    33  ```
    34  
    35  Then, before starting the Docker service, create your own bridge and give it
    36  whatever configuration you want. Here we will create a simple enough bridge
    37  that we really could just have used the options in the previous section to
    38  customize `docker0`, but it will be enough to illustrate the technique.
    39  
    40  ```
    41  # Create our own bridge
    42  
    43  $ sudo brctl addbr bridge0
    44  $ sudo ip addr add 192.168.5.1/24 dev bridge0
    45  $ sudo ip link set dev bridge0 up
    46  
    47  # Confirming that our bridge is up and running
    48  
    49  $ ip addr show bridge0
    50  4: bridge0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state UP group default
    51      link/ether 66:38:d0:0d:76:18 brd ff:ff:ff:ff:ff:ff
    52      inet 192.168.5.1/24 scope global bridge0
    53         valid_lft forever preferred_lft forever
    54  
    55  # Tell Docker about it and restart (on Ubuntu)
    56  
    57  $ echo 'DOCKER_OPTS="-b=bridge0"' >> /etc/default/docker
    58  $ sudo service docker start
    59  
    60  # Confirming new outgoing NAT masquerade is set up
    61  
    62  $ sudo iptables -t nat -L -n
    63  ...
    64  Chain POSTROUTING (policy ACCEPT)
    65  target     prot opt source               destination
    66  MASQUERADE  all  --  192.168.5.0/24      0.0.0.0/0
    67  ```
    68  
    69  The result should be that the Docker server starts successfully and is now
    70  prepared to bind containers to the new bridge. After pausing to verify the
    71  bridge's configuration, try creating a container -- you will see that its IP
    72  address is in your new IP address range, which Docker will have auto-detected.
    73  
    74  You can use the `brctl show` command to see Docker add and remove interfaces
    75  from the bridge as you start and stop containers, and can run `ip addr` and `ip
    76  route` inside a container to see that it has been given an address in the
    77  bridge's IP address range and has been told to use the Docker host's IP address
    78  on the bridge as its default gateway to the rest of the Internet.