diff options
Diffstat (limited to 'libpod/runtime_ctr.go')
-rw-r--r-- | libpod/runtime_ctr.go | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go index fd92a3411..9a91e0a48 100644 --- a/libpod/runtime_ctr.go +++ b/libpod/runtime_ctr.go @@ -7,6 +7,8 @@ import ( "github.com/sirupsen/logrus" ) +const ctrRemoveTimeout = 10 + // Contains the public Runtime API for containers // A CtrCreateOption is a functional option which alters the Container created @@ -97,7 +99,11 @@ func (r *Runtime) RemoveContainer(c *Container, force bool) error { } // Check that the container's in a good state to be removed - if !(c.state.State == ContainerStateConfigured || + if c.state.State == ContainerStateRunning && force { + if err := r.ociRuntime.stopContainer(c, ctrRemoveTimeout); err != nil { + return errors.Wrapf(err, "cannot remove container %s as it could not be stopped", c.ID()) + } + } else if !(c.state.State == ContainerStateConfigured || c.state.State == ContainerStateCreated || c.state.State == ContainerStateStopped) { return errors.Wrapf(ErrCtrStateInvalid, "cannot remove container %s as it is running or paused", c.ID()) @@ -112,6 +118,11 @@ func (r *Runtime) RemoveContainer(c *Container, force bool) error { return errors.Wrapf(err, "error removing container from state") } + // Delete the container + if err := r.ociRuntime.deleteContainer(c); err != nil { + return errors.Wrapf(err, "error removing container %s from runc", c.ID()) + } + // Set container as invalid so it can no longer be used c.valid = false |