diff --git a/libpod/container_internal.go b/libpod/container_internal.go index 3fcf687eca..5baa5fc1c0 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -1562,6 +1562,18 @@ func (c *Container) cleanup(ctx context.Context) error { lastError = errors.Wrapf(err, "error removing container %s network", c.ID()) } + // Remove the container from the runtime, if necessary. + // Do this *before* unmounting storage - some runtimes (e.g. Kata) + // apparently object to having storage removed while the container still + // exists. + if err := c.cleanupRuntime(ctx); err != nil { + if lastError != nil { + logrus.Errorf("Error removing container %s from OCI runtime: %v", c.ID(), err) + } else { + lastError = err + } + } + // Unmount storage if err := c.cleanupStorage(); err != nil { if lastError != nil { @@ -1571,15 +1583,6 @@ func (c *Container) cleanup(ctx context.Context) error { } } - // Remove the container from the runtime, if necessary - if err := c.cleanupRuntime(ctx); err != nil { - if lastError != nil { - logrus.Errorf("Error removing container %s from OCI runtime: %v", c.ID(), err) - } else { - lastError = err - } - } - return lastError }