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

run --rmi: "cannot remove" is a warning, not an error #19891

Merged
merged 1 commit into from
Sep 9, 2023
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
10 changes: 7 additions & 3 deletions cmd/podman/containers/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import (
"github.com/containers/podman/v4/cmd/podman/utils"
"github.com/containers/podman/v4/libpod/define"
"github.com/containers/podman/v4/pkg/domain/entities"
"github.com/containers/podman/v4/pkg/errorhandling"
"github.com/containers/podman/v4/pkg/rootless"
"github.com/containers/podman/v4/pkg/specgen"
"github.com/containers/podman/v4/pkg/specgenutil"
"github.com/containers/storage/types"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"golang.org/x/term"
Expand Down Expand Up @@ -226,8 +226,12 @@ func run(cmd *cobra.Command, args []string) error {
}
if runRmi {
_, rmErrors := registry.ImageEngine().Remove(registry.GetContext(), []string{imageName}, entities.ImageRemoveOptions{})
if len(rmErrors) > 0 {
logrus.Errorf("%s", errorhandling.JoinErrors(rmErrors))
for _, err := range rmErrors {
// ImageUnknown would be a super-unlikely race
if !errors.Is(err, types.ErrImageUnknown) {
// Typical case: ErrImageUsedByContainer
logrus.Warn(err)
}
}
}
if cmd.Flag("gpus").Changed {
Expand Down
2 changes: 1 addition & 1 deletion test/system/030-run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ echo $rand | 0 | $rand
run_podman image exists $NONLOCAL_IMAGE

# Now try running with --rmi : it should succeed, but not remove the image
run_podman 0+e run --rmi --rm $NONLOCAL_IMAGE /bin/true
run_podman 0+w run --rmi --rm $NONLOCAL_IMAGE /bin/true
is "$output" ".*image is in use by a container" "--rmi should warn that the image was not removed"
run_podman image exists $NONLOCAL_IMAGE

Expand Down
2 changes: 1 addition & 1 deletion test/upgrade/test-upgrade.bats
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ failed | exited | 17


@test "stop and rm" {
run_podman stop myrunningcontainer
run_podman 0+w stop myrunningcontainer
run_podman rm myrunningcontainer
}

Expand Down