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