Skip to content

Commit

Permalink
Remove a volume with --force if container is running
Browse files Browse the repository at this point in the history
Currently we are not passing the force flag down to the removal of
the running container. If the container is running, and we set
--force when removing the volume, the container should be stopped.

Signed-off-by: Daniel J Walsh <[email protected]>
  • Loading branch information
rhatdan committed Oct 11, 2021
1 parent 00ebf3c commit 7580c22
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 7580c22

Please sign in to comment.