- Do not create the default "bridge" network
- Get rid of the docker0 bridge
Signed-off-by: Alessandro Boch <aboch@docker.com>
| ... | ... |
@@ -39,6 +39,7 @@ import ( |
| 39 | 39 |
"github.com/opencontainers/runc/libcontainer/label" |
| 40 | 40 |
"github.com/opencontainers/runc/libcontainer/user" |
| 41 | 41 |
"github.com/opencontainers/runtime-spec/specs-go" |
| 42 |
+ "github.com/vishvananda/netlink" |
|
| 42 | 43 |
) |
| 43 | 44 |
|
| 44 | 45 |
const ( |
| ... | ... |
@@ -637,11 +638,21 @@ func (daemon *Daemon) initNetworkController(config *Config, activeSandboxes map[ |
| 637 | 637 |
return nil, fmt.Errorf("Error creating default \"host\" network: %v", err)
|
| 638 | 638 |
} |
| 639 | 639 |
} |
| 640 |
+ |
|
| 641 |
+ // Clear stale bridge network |
|
| 642 |
+ if n, err := controller.NetworkByName("bridge"); err == nil {
|
|
| 643 |
+ if err = n.Delete(); err != nil {
|
|
| 644 |
+ return nil, fmt.Errorf("could not delete the default bridge network: %v", err)
|
|
| 645 |
+ } |
|
| 646 |
+ } |
|
| 647 |
+ |
|
| 640 | 648 |
if !config.DisableBridge {
|
| 641 | 649 |
// Initialize default driver "bridge" |
| 642 | 650 |
if err := initBridgeDriver(controller, config); err != nil {
|
| 643 | 651 |
return nil, err |
| 644 | 652 |
} |
| 653 |
+ } else {
|
|
| 654 |
+ removeDefaultBridgeInterface() |
|
| 645 | 655 |
} |
| 646 | 656 |
|
| 647 | 657 |
return controller, nil |
| ... | ... |
@@ -660,12 +671,6 @@ func driverOptions(config *Config) []nwconfig.Option {
|
| 660 | 660 |
} |
| 661 | 661 |
|
| 662 | 662 |
func initBridgeDriver(controller libnetwork.NetworkController, config *Config) error {
|
| 663 |
- if n, err := controller.NetworkByName("bridge"); err == nil {
|
|
| 664 |
- if err = n.Delete(); err != nil {
|
|
| 665 |
- return fmt.Errorf("could not delete the default bridge network: %v", err)
|
|
| 666 |
- } |
|
| 667 |
- } |
|
| 668 |
- |
|
| 669 | 663 |
bridgeName := bridge.DefaultBridgeName |
| 670 | 664 |
if config.bridgeConfig.Iface != "" {
|
| 671 | 665 |
bridgeName = config.bridgeConfig.Iface |
| ... | ... |
@@ -779,6 +784,15 @@ func initBridgeDriver(controller libnetwork.NetworkController, config *Config) e |
| 779 | 779 |
return nil |
| 780 | 780 |
} |
| 781 | 781 |
|
| 782 |
+// Remove default bridge interface if present (--bridge=none use case) |
|
| 783 |
+func removeDefaultBridgeInterface() {
|
|
| 784 |
+ if lnk, err := netlink.LinkByName(bridge.DefaultBridgeName); err == nil {
|
|
| 785 |
+ if err := netlink.LinkDel(lnk); err != nil {
|
|
| 786 |
+ logrus.Warnf("Failed to remove bridge interface (%s): %v", bridge.DefaultBridgeName, err)
|
|
| 787 |
+ } |
|
| 788 |
+ } |
|
| 789 |
+} |
|
| 790 |
+ |
|
| 782 | 791 |
func (daemon *Daemon) getLayerInit() func(string) error {
|
| 783 | 792 |
return daemon.setupInitLayer |
| 784 | 793 |
} |
| ... | ... |
@@ -643,6 +643,24 @@ func (s *DockerDaemonSuite) TestDaemonBridgeExternal(c *check.C) {
|
| 643 | 643 |
containerIP)) |
| 644 | 644 |
} |
| 645 | 645 |
|
| 646 |
+func (s *DockerDaemonSuite) TestDaemonBridgeNone(c *check.C) {
|
|
| 647 |
+ // start with bridge none |
|
| 648 |
+ d := s.d |
|
| 649 |
+ err := d.StartWithBusybox("--bridge", "none")
|
|
| 650 |
+ c.Assert(err, check.IsNil) |
|
| 651 |
+ defer d.Restart() |
|
| 652 |
+ |
|
| 653 |
+ // verify docker0 iface is not there |
|
| 654 |
+ out, _, err := runCommandWithOutput(exec.Command("ifconfig", "docker0"))
|
|
| 655 |
+ c.Assert(err, check.NotNil, check.Commentf("docker0 should not be present if daemon started with --bridge=none"))
|
|
| 656 |
+ c.Assert(strings.Contains(out, "Device not found"), check.Equals, true) |
|
| 657 |
+ |
|
| 658 |
+ // verify default "bridge" network is not there |
|
| 659 |
+ out, err = d.Cmd("network", "inspect", "bridge")
|
|
| 660 |
+ c.Assert(err, check.NotNil, check.Commentf("\"bridge\" network should not be present if daemon started with --bridge=none"))
|
|
| 661 |
+ c.Assert(strings.Contains(out, "No such network"), check.Equals, true) |
|
| 662 |
+} |
|
| 663 |
+ |
|
| 646 | 664 |
func createInterface(c *check.C, ifType string, ifName string, ipNet string) (string, error) {
|
| 647 | 665 |
args := []string{"link", "add", "name", ifName, "type", ifType}
|
| 648 | 666 |
ipLinkCmd := exec.Command("ip", args...)
|