mirror of
https://github.com/containers/podman.git
synced 2025-05-29 22:46:25 +08:00
Prevent containers with dependencies from being removed
Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #220 Approved by: rhatdan
This commit is contained in:
@ -3,6 +3,7 @@ package libpod
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
spec "github.com/opencontainers/runtime-spec/specs-go"
|
||||
@ -124,6 +125,16 @@ func (r *Runtime) removeContainer(c *Container, force bool) error {
|
||||
return errors.Wrapf(ErrCtrStateInvalid, "container %s is paused, cannot remove until unpaused", c.ID())
|
||||
}
|
||||
|
||||
// Check that no other containers depend on the container
|
||||
deps, err := r.state.ContainerInUse(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(deps) != 0 {
|
||||
depsStr := strings.Join(deps, ", ")
|
||||
return errors.Wrapf(ErrCtrExists, "container %s has dependent containers which must be removed before it: %s", c.ID(), depsStr)
|
||||
}
|
||||
|
||||
// Check that the container's in a good state to be removed
|
||||
if c.state.State == ContainerStateRunning && force {
|
||||
if err := r.ociRuntime.stopContainer(c, c.StopTimeout()); err != nil {
|
||||
|
Reference in New Issue
Block a user