This fix tries to address the issue raised in 26220 where
disconnecting a container from network does not work if
the network id (instead of network name) has been specified.
The issue was that internally when trying to disconnecting
a contaienr fromt the network, the originally passed network
name or id has been used.
This fix uses the resolved network name (e.g., `bridge`).
An integration test has been added to cover the changes.
This fix fixes 26220.
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
| ... | ... |
@@ -129,6 +129,11 @@ func (daemon *Daemon) DisconnectFromNetwork(container *container.Container, netw |
| 129 | 129 |
if container.RemovalInProgress || container.Dead {
|
| 130 | 130 |
return errRemovalContainer(container.ID) |
| 131 | 131 |
} |
| 132 |
+ // In case networkName is resolved we will use n.Name() |
|
| 133 |
+ // this will cover the case where network id is passed. |
|
| 134 |
+ if n != nil {
|
|
| 135 |
+ networkName = n.Name() |
|
| 136 |
+ } |
|
| 132 | 137 |
if _, ok := container.NetworkSettings.Networks[networkName]; !ok {
|
| 133 | 138 |
return fmt.Errorf("container %s is not connected to the network %s", container.ID, networkName)
|
| 134 | 139 |
} |
| ... | ... |
@@ -1756,3 +1756,16 @@ func (s *DockerNetworkSuite) TestDockerNetworkValidateIP(c *check.C) {
|
| 1756 | 1756 |
_, _, err = dockerCmdWithError("run", "--net=mynet", "--ip6", "::ffff:172.28.99.99", "busybox", "top")
|
| 1757 | 1757 |
c.Assert(err.Error(), checker.Contains, "invalid IPv6 address") |
| 1758 | 1758 |
} |
| 1759 |
+ |
|
| 1760 |
+// Test case for 26220 |
|
| 1761 |
+func (s *DockerNetworkSuite) TestDockerNetworkDisconnectFromBridge(c *check.C) {
|
|
| 1762 |
+ out, _ := dockerCmd(c, "network", "inspect", "--format", "{{.Id}}", "bridge")
|
|
| 1763 |
+ |
|
| 1764 |
+ network := strings.TrimSpace(out) |
|
| 1765 |
+ |
|
| 1766 |
+ name := "test" |
|
| 1767 |
+ dockerCmd(c, "create", "--rm", "--name", name, "busybox", "top") |
|
| 1768 |
+ |
|
| 1769 |
+ _, _, err := dockerCmdWithError("network", "disconnect", network, name)
|
|
| 1770 |
+ c.Assert(err, check.IsNil) |
|
| 1771 |
+} |