Skip to content

Commit

Permalink
Merge pull request containers#11925 from rhatdan/volume
Browse files Browse the repository at this point in the history
Remove a volume with --force if container is running
  • Loading branch information
openshift-merge-robot authored Oct 12, 2021
2 parents 03095bd + 7580c22 commit c90beed
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 1 addition & 5 deletions libpod/runtime_volume_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,7 @@ func (r *Runtime) removeVolume(ctx context.Context, v *Volume, force bool, timeo

logrus.Debugf("Removing container %s (depends on volume %q)", ctr.ID(), v.Name())

// TODO: do we want to set force here when removing
// containers?
// I'm inclined to say no, in case someone accidentally
// wipes a container they're using...
if err := r.removeContainer(ctx, ctr, false, false, false, timeout); err != nil {
if err := r.removeContainer(ctx, ctr, force, false, false, timeout); err != nil {
return errors.Wrapf(err, "error removing container %s that depends on volume %s", ctr.ID(), v.Name())
}
}
Expand Down
8 changes: 8 additions & 0 deletions test/system/160-volumes.bats
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ Labels.l | $mylabel
run_podman volume rm $myvolume
}

# Removing volumes with --force
@test "podman volume rm --force" {
run_podman run -d --volume myvol:/myvol $IMAGE top
cid=$output
run_podman 2 volume rm myvol
is "$output" "Error: volume myvol is being used by the following container(s): $cid: volume is being used" "should error since container is running"
run_podman volume rm myvol --force
}

# Running scripts (executables) from a volume
@test "podman volume: exec/noexec" {
Expand Down

0 comments on commit c90beed

Please sign in to comment.