bugfix: report "destroy" after all volumes of container destroy
fixes #25766 If a container's AutoRemove is enabled, client will wait until it's removed after container exits, this is implemented based on "destroy" event. Currently an "AutoRemove" container will report "destroy" event to notify a hanging client to exit before all volumes are removed, this is wrong, we should wait container until everything is cleaned up. Signed-off-by: Zhang Wei <zhangwei555@huawei.com> Upstream-commit: 4df77c11e065bf96b04fc0328a7e7600a2e64937 Component: engine
This commit is contained in:
@ -90,7 +90,7 @@ func (daemon *Daemon) create(params types.ContainerCreateConfig, managed bool) (
|
||||
}
|
||||
defer func() {
|
||||
if retErr != nil {
|
||||
if err := daemon.cleanupContainer(container, true); err != nil {
|
||||
if err := daemon.cleanupContainer(container, true, true); err != nil {
|
||||
logrus.Errorf("failed to cleanup container on create error: %v", err)
|
||||
}
|
||||
}
|
||||
@ -118,13 +118,6 @@ func (daemon *Daemon) create(params types.ContainerCreateConfig, managed bool) (
|
||||
if err := daemon.setHostConfig(container, params.HostConfig); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer func() {
|
||||
if retErr != nil {
|
||||
if err := daemon.removeMountPoints(container, true); err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
if err := daemon.createContainerPlatformSpecificSettings(container, params.Config, params.HostConfig); err != nil {
|
||||
return nil, err
|
||||
|
||||
@ -39,14 +39,7 @@ func (daemon *Daemon) ContainerRm(name string, config *types.ContainerRmConfig)
|
||||
return daemon.rmLink(container, name)
|
||||
}
|
||||
|
||||
err = daemon.cleanupContainer(container, config.ForceRemove)
|
||||
if err == nil || config.ForceRemove {
|
||||
if e := daemon.removeMountPoints(container, config.RemoveVolume); e != nil {
|
||||
logrus.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
return daemon.cleanupContainer(container, config.ForceRemove, config.RemoveVolume)
|
||||
}
|
||||
|
||||
func (daemon *Daemon) rmLink(container *container.Container, name string) error {
|
||||
@ -77,7 +70,7 @@ func (daemon *Daemon) rmLink(container *container.Container, name string) error
|
||||
|
||||
// cleanupContainer unregisters a container from the daemon, stops stats
|
||||
// collection and cleanly removes contents and metadata from the filesystem.
|
||||
func (daemon *Daemon) cleanupContainer(container *container.Container, forceRemove bool) (err error) {
|
||||
func (daemon *Daemon) cleanupContainer(container *container.Container, forceRemove, removeVolume bool) (err error) {
|
||||
if container.IsRunning() {
|
||||
if !forceRemove {
|
||||
err := fmt.Errorf("You cannot remove a running container %s. Stop the container before attempting removal or use -f", container.ID)
|
||||
@ -115,6 +108,9 @@ func (daemon *Daemon) cleanupContainer(container *container.Container, forceRemo
|
||||
selinuxFreeLxcContexts(container.ProcessLabel)
|
||||
daemon.idIndex.Delete(container.ID)
|
||||
daemon.containers.Delete(container.ID)
|
||||
if e := daemon.removeMountPoints(container, removeVolume); e != nil {
|
||||
logrus.Error(e)
|
||||
}
|
||||
daemon.LogContainerEvent(container, "destroy")
|
||||
}
|
||||
}()
|
||||
|
||||
Reference in New Issue
Block a user