Ver código fonte

Merge pull request #38364 from cpuguy83/fix_stale_container_on_start

Delete stale containerd object on start failure
Brian Goff 6 anos atrás
pai
commit
fcb286895b
1 arquivos alterados com 15 adições e 2 exclusões
  1. 15 2
      daemon/start.go

+ 15 - 2
daemon/start.go

@@ -177,9 +177,22 @@ func (daemon *Daemon) containerStart(container *container.Container, checkpoint
 		return err
 		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 err != nil {
-		return translateContainerdStartErr(container.Path, container.SetExitCode, err)
+		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
 	// TODO(mlaventure): we need to specify checkpoint options here