diff --git a/daemon/container.go b/daemon/container.go index 7062d6796..fd3d79659 100644 --- a/daemon/container.go +++ b/daemon/container.go @@ -446,8 +446,17 @@ func (container *Container) allocateNetwork() error { if container.Config.ExposedPorts != nil { portSpecs = container.Config.ExposedPorts } + if container.hostConfig.PortBindings != nil { - bindings = container.hostConfig.PortBindings + for p, b := range container.hostConfig.PortBindings { + bindings[p] = []nat.PortBinding{} + for _, bb := range b { + bindings[p] = append(bindings[p], nat.PortBinding{ + HostIp: bb.HostIp, + HostPort: bb.HostPort, + }) + } + } } container.NetworkSettings.PortMapping = nil diff --git a/daemon/daemon.go b/daemon/daemon.go index d3f73f413..8d7d7764b 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -209,6 +209,7 @@ func (daemon *Daemon) register(container *Container, updateSuffixarray bool, con } daemon.execDriver.Terminate(cmd) } + if err := container.Unmount(); err != nil { utils.Debugf("unmount error %s", err) } @@ -219,21 +220,20 @@ func (daemon *Daemon) register(container *Container, updateSuffixarray bool, con info := daemon.execDriver.Info(container.ID) if !info.IsRunning() { utils.Debugf("Container %s was supposed to be running but is not.", container.ID) + + utils.Debugf("Marking as stopped") + + container.State.SetStopped(-127) + if err := container.ToDisk(); err != nil { + return err + } + if daemon.config.AutoRestart { utils.Debugf("Marking as restarting") - if err := container.Unmount(); err != nil { - utils.Debugf("restart unmount error %s", err) - } if containersToStart != nil { *containersToStart = append(*containersToStart, container) } - } else { - utils.Debugf("Marking as stopped") - container.State.SetStopped(-127) - if err := container.ToDisk(); err != nil { - return err - } } } }