Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove a volume with --force if container is running #11925

Merged
merged 1 commit into from
Oct 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to add a check here, to make sure $cid is stopped?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I figured it was since the rm failed previously complaining about the running container. When this is done the $cid should no longer exists.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. So wouldn't it be nice to confirm it? run_podman 1 container exists $cid ? But I can add it in one of my future grab-bag bats PRs

}

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