Try to force delete ctr when in paused state
@@ -20,17 +20,23 @@ func (c *ContainerServer) Remove(ctx context.Context, container string, force bo
cStatus := ctr.State()
switch cStatus.Status {
case oci.ContainerStatePaused:
- return "", errors.Errorf("cannot remove paused container %s", ctrID)
- case oci.ContainerStateCreated, oci.ContainerStateRunning:
if force {
- if err = c.StopContainer(ctx, ctr, 10); err != nil {
- return "", errors.Wrapf(err, "unable to stop container %s", ctrID)
+ if err = c.runtime.UnpauseContainer(ctx, ctr); err != nil {
+ return "", errors.Wrapf(err, "unable to unpause container %s", ctrID)
}
} else {
+ return "", errors.Errorf("cannot remove paused container %s", ctrID)
+ }
+ case oci.ContainerStateCreated, oci.ContainerStateRunning:
+ if !force {
return "", errors.Errorf("cannot remove running container %s", ctrID)
}
}
+ if err = c.StopContainer(ctx, ctr, 10); err != nil {
+ return "", errors.Wrapf(err, "unable to stop container %s", ctrID)
+ }
+
if err := c.runtime.DeleteContainer(ctx, ctr); err != nil {
return "", errors.Wrapf(err, "failed to delete container %s", ctrID)
}
