Skip to content
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
9 changes: 6 additions & 3 deletions cli/command/image/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ func runRemove(dockerCli command.Cli, opts removeOptions, images []string) error
}

var errs []string
for _, image := range images {
dels, err := client.ImageRemove(ctx, image, options)
for _, img := range images {
dels, err := client.ImageRemove(ctx, img, options)
if err != nil {
if opts.force {
fmt.Fprintf(dockerCli.Out(), "NotFound: %s\n", img)
}
errs = append(errs, err.Error())
} else {
for _, del := range dels {
Expand All @@ -71,7 +74,7 @@ func runRemove(dockerCli command.Cli, opts removeOptions, images []string) error
}
}

if len(errs) > 0 {
if !opts.force && len(errs) > 0 {
return errors.Errorf("%s", strings.Join(errs, "\n"))
}
return nil
Expand Down
8 changes: 8 additions & 0 deletions cli/command/image/remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ func TestNewRemoveCommandSuccess(t *testing.T) {
return []types.ImageDeleteResponseItem{{Deleted: image}}, nil
},
},
{
name: "Image Deleted with force option",
args: []string{"-f", "image1"},
imageRemoveFunc: func(image string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error) {
assert.Equal(t, "image1", image)
return []types.ImageDeleteResponseItem{}, errors.Errorf("error removing image")
},
},
{
name: "Image Untagged",
args: []string{"image1"},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NotFound:image1
Copy link
Member

Choose a reason for hiding this comment

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

Was discussing with @vdemeester that the naming of these files is a bit odd; perhaps we should normalise them to be lowercase and have spaces replaced with -. Given that these files are generated, and this is in line with other files in this tests, we can keep it for now 👍

NotFound:image1