mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
fix 2 corner cases in container create cleanup and container removal
- avoid empty Names in container list API when fails to remove a container - avoid dead containers when fails to create a container Signed-off-by: Shijiang Wei <mountkin@gmail.com>
This commit is contained in:
parent
f187bdbb9b
commit
4953ea1eae
2 changed files with 9 additions and 15 deletions
|
@ -76,7 +76,7 @@ func (daemon *Daemon) create(params *ContainerCreateConfig) (retC *Container, re
|
|||
}
|
||||
defer func() {
|
||||
if retErr != nil {
|
||||
if err := daemon.rm(container, false); err != nil {
|
||||
if err := daemon.rm(container, true); err != nil {
|
||||
logrus.Errorf("Clean up Error! Cannot destroy container %s: %v", container.ID, err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,37 +107,31 @@ func (daemon *Daemon) rm(container *Container, forceRemove bool) (err error) {
|
|||
// If force removal is required, delete container from various
|
||||
// indexes even if removal failed.
|
||||
defer func() {
|
||||
if err != nil && forceRemove {
|
||||
if err == nil || forceRemove {
|
||||
if _, err := daemon.containerGraphDB.Purge(container.ID); err != nil {
|
||||
logrus.Debugf("Unable to remove container from link graph: %s", err)
|
||||
}
|
||||
selinuxFreeLxcContexts(container.ProcessLabel)
|
||||
daemon.idIndex.Delete(container.ID)
|
||||
daemon.containers.Delete(container.ID)
|
||||
os.RemoveAll(container.root)
|
||||
daemon.LogContainerEvent(container, "destroy")
|
||||
}
|
||||
}()
|
||||
|
||||
if _, err := daemon.containerGraphDB.Purge(container.ID); err != nil {
|
||||
logrus.Debugf("Unable to remove container from link graph: %s", err)
|
||||
if err = os.RemoveAll(container.root); err != nil {
|
||||
return derr.ErrorCodeRmFS.WithArgs(container.ID, err)
|
||||
}
|
||||
|
||||
metadata, err := daemon.layerStore.DeleteMount(container.ID)
|
||||
layer.LogReleaseMetadata(metadata)
|
||||
if err != nil {
|
||||
if err != nil && err != layer.ErrMountDoesNotExist {
|
||||
return derr.ErrorCodeRmDriverFS.WithArgs(daemon.driver, container.ID, err)
|
||||
}
|
||||
|
||||
if err = os.RemoveAll(container.root); err != nil {
|
||||
return derr.ErrorCodeRmFS.WithArgs(container.ID, err)
|
||||
}
|
||||
|
||||
if err = daemon.execDriver.Clean(container.ID); err != nil {
|
||||
return derr.ErrorCodeRmExecDriver.WithArgs(container.ID, err)
|
||||
}
|
||||
|
||||
selinuxFreeLxcContexts(container.ProcessLabel)
|
||||
daemon.idIndex.Delete(container.ID)
|
||||
daemon.containers.Delete(container.ID)
|
||||
|
||||
daemon.LogContainerEvent(container, "destroy")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue