Merge pull request #154 from thaJeztah/18.09_backport_fix_stale_container_on_start

[18.09 backport] Delete stale containerd object on start failure
This commit is contained in:
Andrew Hsu 2019-02-22 13:52:47 -08:00 committed by GitHub
commit ba8664cc22
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -176,10 +176,23 @@ func (daemon *Daemon) containerStart(container *container.Container, checkpoint
return err
}
err = daemon.containerd.Create(context.Background(), container.ID, spec, createOptions)
ctx := context.TODO()
err = daemon.containerd.Create(ctx, container.ID, spec, createOptions)
if err != nil {
if errdefs.IsConflict(err) {
logrus.WithError(err).WithField("container", container.ID).Error("Container not cleaned up from containerd from previous run")
// best effort to clean up old container object
daemon.containerd.DeleteTask(ctx, container.ID)
if err := daemon.containerd.Delete(ctx, container.ID); err != nil && !errdefs.IsNotFound(err) {
logrus.WithError(err).WithField("container", container.ID).Error("Error cleaning up stale containerd container object")
}
err = daemon.containerd.Create(ctx, container.ID, spec, createOptions)
}
if err != nil {
return translateContainerdStartErr(container.Path, container.SetExitCode, err)
}
}
// TODO(mlaventure): we need to specify checkpoint options here
pid, err := daemon.containerd.Start(context.Background(), container.ID, checkpointDir,