1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #7163 from crosbymichael/fix-port-mapping-on-restart

Always mark as stopped for non running containers
This commit is contained in:
Victor Vieux 2014-07-22 16:55:46 -07:00
commit 9e1a9a7d98
2 changed files with 19 additions and 10 deletions

View file

@ -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

View file

@ -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
}
}
}
}