From 3cb14df68c1a59981907fec3bccab80a1d0dda59 Mon Sep 17 00:00:00 2001 From: Alexander Morozov Date: Sun, 24 May 2015 08:26:56 -0700 Subject: [PATCH] Fix network with -b none * Don't AllocateNetwork when network is disabled * Don't createNetwork in execdriver when network is disabled Signed-off-by: Alexander Morozov --- daemon/container_linux.go | 25 +++++++++++++---------- daemon/execdriver/native/create.go | 3 +++ integration-cli/docker_cli_daemon_test.go | 9 ++++++++ 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/daemon/container_linux.go b/daemon/container_linux.go index f499235a72..76598fa3a8 100644 --- a/daemon/container_linux.go +++ b/daemon/container_linux.go @@ -182,17 +182,20 @@ func getDevicesFromPath(deviceMapping runconfig.DeviceMapping) (devs []*configs. } func populateCommand(c *Container, env []string) error { - en := &execdriver.Network{ - NamespacePath: c.NetworkSettings.SandboxKey, - } - - parts := strings.SplitN(string(c.hostConfig.NetworkMode), ":", 2) - if parts[0] == "container" { - nc, err := c.getNetworkedContainer() - if err != nil { - return err + var en *execdriver.Network + if !c.daemon.config.DisableNetwork { + en = &execdriver.Network{ + NamespacePath: c.NetworkSettings.SandboxKey, + } + + parts := strings.SplitN(string(c.hostConfig.NetworkMode), ":", 2) + if parts[0] == "container" { + nc, err := c.getNetworkedContainer() + if err != nil { + return err + } + en.ContainerID = nc.ID } - en.ContainerID = nc.ID } ipc := &execdriver.Ipc{} @@ -906,7 +909,7 @@ func (container *Container) getNetworkedContainer() (*Container, error) { } func (container *Container) ReleaseNetwork() { - if container.hostConfig.NetworkMode.IsContainer() { + if container.hostConfig.NetworkMode.IsContainer() || container.daemon.config.DisableNetwork { return } diff --git a/daemon/execdriver/native/create.go b/daemon/execdriver/native/create.go index 6d2a1e8c45..1b2d7232d3 100644 --- a/daemon/execdriver/native/create.go +++ b/daemon/execdriver/native/create.go @@ -89,6 +89,9 @@ func generateIfaceName() (string, error) { } func (d *driver) createNetwork(container *configs.Config, c *execdriver.Command) error { + if c.Network == nil { + return nil + } if c.Network.ContainerID != "" { d.Lock() active := d.activeContainers[c.Network.ContainerID] diff --git a/integration-cli/docker_cli_daemon_test.go b/integration-cli/docker_cli_daemon_test.go index e6c1255d4c..d668781dcf 100644 --- a/integration-cli/docker_cli_daemon_test.go +++ b/integration-cli/docker_cli_daemon_test.go @@ -1156,3 +1156,12 @@ func (s *DockerDaemonSuite) TestCleanupMountsAfterCrash(c *check.C) { c.Assert(err, check.IsNil, check.Commentf("Output: %s", mountOut)) c.Assert(strings.Contains(string(mountOut), id), check.Equals, false, check.Commentf("Something mounted from older daemon start: %s", mountOut)) } + +func (s *DockerDaemonSuite) TestRunContainerWithBridgeNone(c *check.C) { + c.Assert(s.d.StartWithBusybox("-b", "none"), check.IsNil) + + out, err := s.d.Cmd("run", "--rm", "busybox", "ip", "l") + c.Assert(err, check.IsNil, check.Commentf("Output: %s", out)) + c.Assert(strings.Contains(out, "eth0"), check.Equals, false, + check.Commentf("There shouldn't be eth0 in container when network is disabled: %s", out)) +}