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 <lk4d4@docker.com>
This commit is contained in:
parent
f83073d3eb
commit
3cb14df68c
3 changed files with 26 additions and 11 deletions
|
@ -182,17 +182,20 @@ func getDevicesFromPath(deviceMapping runconfig.DeviceMapping) (devs []*configs.
|
||||||
}
|
}
|
||||||
|
|
||||||
func populateCommand(c *Container, env []string) error {
|
func populateCommand(c *Container, env []string) error {
|
||||||
en := &execdriver.Network{
|
var en *execdriver.Network
|
||||||
NamespacePath: c.NetworkSettings.SandboxKey,
|
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()
|
parts := strings.SplitN(string(c.hostConfig.NetworkMode), ":", 2)
|
||||||
if err != nil {
|
if parts[0] == "container" {
|
||||||
return err
|
nc, err := c.getNetworkedContainer()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
en.ContainerID = nc.ID
|
||||||
}
|
}
|
||||||
en.ContainerID = nc.ID
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ipc := &execdriver.Ipc{}
|
ipc := &execdriver.Ipc{}
|
||||||
|
@ -906,7 +909,7 @@ func (container *Container) getNetworkedContainer() (*Container, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (container *Container) ReleaseNetwork() {
|
func (container *Container) ReleaseNetwork() {
|
||||||
if container.hostConfig.NetworkMode.IsContainer() {
|
if container.hostConfig.NetworkMode.IsContainer() || container.daemon.config.DisableNetwork {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,6 +89,9 @@ func generateIfaceName() (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *driver) createNetwork(container *configs.Config, c *execdriver.Command) error {
|
func (d *driver) createNetwork(container *configs.Config, c *execdriver.Command) error {
|
||||||
|
if c.Network == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
if c.Network.ContainerID != "" {
|
if c.Network.ContainerID != "" {
|
||||||
d.Lock()
|
d.Lock()
|
||||||
active := d.activeContainers[c.Network.ContainerID]
|
active := d.activeContainers[c.Network.ContainerID]
|
||||||
|
|
|
@ -1156,3 +1156,12 @@ func (s *DockerDaemonSuite) TestCleanupMountsAfterCrash(c *check.C) {
|
||||||
c.Assert(err, check.IsNil, check.Commentf("Output: %s", mountOut))
|
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))
|
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))
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue