mirror of
https://github.com/clearlinux/docker.git
synced 2026-09-06 13:41:36 +00:00
Prevent connecting to host and prevent disconnecting from host
Container has private network namespace can not to connect to host and container with host network can not be disconnected from host. Signed-off-by: Lei Jitang <leijitang@huawei.com> (cherry picked from commit a2d8c93fc690c2244a3bed32a2bbeb8dae449f90)
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/versions/v1p20"
|
||||
"github.com/docker/docker/pkg/integration/checker"
|
||||
"github.com/docker/docker/runconfig"
|
||||
"github.com/docker/libnetwork/driverapi"
|
||||
remoteapi "github.com/docker/libnetwork/drivers/remote/api"
|
||||
"github.com/docker/libnetwork/ipamapi"
|
||||
@@ -730,3 +731,20 @@ func (s *DockerNetworkSuite) TestDockerNetworkRunNetByID(c *check.C) {
|
||||
out, _ := dockerCmd(c, "network", "create", "one")
|
||||
dockerCmd(c, "run", "-d", "--net", strings.TrimSpace(out), "busybox", "top")
|
||||
}
|
||||
|
||||
func (s *DockerNetworkSuite) TestDockerNetworkConnectToHostFromOtherNetwork(c *check.C) {
|
||||
dockerCmd(c, "run", "-d", "--name", "container1", "busybox", "top")
|
||||
c.Assert(waitRun("container1"), check.IsNil)
|
||||
dockerCmd(c, "network", "disconnect", "bridge", "container1")
|
||||
out, _, err := dockerCmdWithError("network", "connect", "host", "container1")
|
||||
c.Assert(err, checker.NotNil, check.Commentf(out))
|
||||
c.Assert(out, checker.Contains, runconfig.ErrConflictHostNetwork.Error())
|
||||
}
|
||||
|
||||
func (s *DockerNetworkSuite) TestDockerNetworkDisconnectFromHost(c *check.C) {
|
||||
dockerCmd(c, "run", "-d", "--name", "container1", "--net=host", "busybox", "top")
|
||||
c.Assert(waitRun("container1"), check.IsNil)
|
||||
out, _, err := dockerCmdWithError("network", "disconnect", "host", "container1")
|
||||
c.Assert(err, checker.NotNil, check.Commentf("Should err out disconnect from host"))
|
||||
c.Assert(out, checker.Contains, runconfig.ErrConflictHostNetwork.Error())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user