Merge pull request #26297 from yongtang/26220-disconnect-container-from-network

Fix issue in disconnecting a container from network
This commit is contained in:
Madhu Venugopal 2016-09-04 21:15:39 -07:00 committed by GitHub
commit 506c51e71e
2 changed files with 18 additions and 0 deletions

View file

@ -129,6 +129,11 @@ func (daemon *Daemon) DisconnectFromNetwork(container *container.Container, netw
if container.RemovalInProgress || container.Dead {
return errRemovalContainer(container.ID)
}
// In case networkName is resolved we will use n.Name()
// this will cover the case where network id is passed.
if n != nil {
networkName = n.Name()
}
if _, ok := container.NetworkSettings.Networks[networkName]; !ok {
return fmt.Errorf("container %s is not connected to the network %s", container.ID, networkName)
}

View file

@ -1756,3 +1756,16 @@ func (s *DockerNetworkSuite) TestDockerNetworkValidateIP(c *check.C) {
_, _, err = dockerCmdWithError("run", "--net=mynet", "--ip6", "::ffff:172.28.99.99", "busybox", "top")
c.Assert(err.Error(), checker.Contains, "invalid IPv6 address")
}
// Test case for 26220
func (s *DockerNetworkSuite) TestDockerNetworkDisconnectFromBridge(c *check.C) {
out, _ := dockerCmd(c, "network", "inspect", "--format", "{{.Id}}", "bridge")
network := strings.TrimSpace(out)
name := "test"
dockerCmd(c, "create", "--rm", "--name", name, "busybox", "top")
_, _, err := dockerCmdWithError("network", "disconnect", network, name)
c.Assert(err, check.IsNil)
}