diff --git a/api.go b/api.go index 8f2befb237..1759257e6e 100644 --- a/api.go +++ b/api.go @@ -450,11 +450,7 @@ func deleteImages(srv *Server, version float64, w http.ResponseWriter, r *http.R return fmt.Errorf("Missing parameter") } name := vars["name"] - force, err := getBoolParam(r.Form.Get("force")) - if err != nil { - return err - } - if err := srv.ImageDelete(name, force); err != nil { + if err := srv.ImageDelete(name); err != nil { return err } w.WriteHeader(http.StatusNoContent) diff --git a/api_test.go b/api_test.go index fb1cd211ad..844d15cc13 100644 --- a/api_test.go +++ b/api_test.go @@ -1268,7 +1268,7 @@ func TestDeleteImages(t *testing.T) { } r := httptest.NewRecorder() - if err := deleteImages(srv, r, req, map[string]string{"name": "test:test"}); err != nil { + if err := deleteImages(srv, API_VERSION, r, req, map[string]string{"name": "test:test"}); err != nil { t.Fatal(err) } if r.Code != http.StatusNoContent { diff --git a/commands.go b/commands.go index 704f5ac48d..2af7e548fc 100644 --- a/commands.go +++ b/commands.go @@ -558,7 +558,6 @@ func (cli *DockerCli) CmdPort(args ...string) error { // 'docker rmi IMAGE' removes all images with the name IMAGE func (cli *DockerCli) CmdRmi(args ...string) error { cmd := Subcmd("rmi", "IMAGE [IMAGE...]", "Remove an image") - force := cmd.Bool("f", false, "Force") if err := cmd.Parse(args); err != nil { return nil } @@ -567,13 +566,8 @@ func (cli *DockerCli) CmdRmi(args ...string) error { return nil } - v := url.Values{} - if *force { - v.Set("force", "1") - } - for _, name := range cmd.Args() { - _, _, err := cli.call("DELETE", "/images/"+name+"?"+v.Encode(), nil) + _, _, err := cli.call("DELETE", "/images/"+name, nil) if err != nil { fmt.Printf("%s", err) } else { diff --git a/server.go b/server.go index d1a089c3a9..2e819728b4 100644 --- a/server.go +++ b/server.go @@ -704,7 +704,7 @@ func (srv *Server) ContainerDestroy(name string, removeVolume bool) error { return nil } -func (srv *Server) ImageDelete(name string, force bool) error { +func (srv *Server) ImageDelete(name string) error { img, err := srv.runtime.repositories.LookupImage(name) if err != nil { return fmt.Errorf("No such image: %s", name) @@ -739,13 +739,17 @@ func (srv *Server) ImageDelete(name string, force bool) error { } } // check is the image to delete isn't parent of another image - if !force { - images, _ := srv.runtime.graph.All() - for _, image := range images { - if imgParent, err := image.GetParent(); err == nil && imgParent != nil { - if imgParent.Id == img.Id { - return fmt.Errorf("Conflict: Can't delete %s otherwise %s will be broken", name, image.ShortId()) + images, _ := srv.runtime.graph.All() + for _, image := range images { + if imgParent, err := image.GetParent(); err == nil && imgParent != nil { + if imgParent.Id == img.Id { + if strings.Contains(img.Id, name) { + return fmt.Errorf("Conflict with %s, %s was not removed", image.ShortId(), name) } + if err := srv.runtime.repositories.Delete(name, tag, img.Id); err != nil { + return err + } + return nil } } } diff --git a/server_test.go b/server_test.go index 743b33d545..541c927b83 100644 --- a/server_test.go +++ b/server_test.go @@ -29,7 +29,7 @@ func TestContainerTagImageDelete(t *testing.T) { t.Errorf("Excepted 3 images, %d found", len(images)) } - if err := srv.ImageDelete("utest/docker:tag2", true); err != nil { + if err := srv.ImageDelete("utest/docker:tag2"); err != nil { t.Fatal(err) } @@ -42,7 +42,7 @@ func TestContainerTagImageDelete(t *testing.T) { t.Errorf("Excepted 2 images, %d found", len(images)) } - if err := srv.ImageDelete("utest:tag1", true); err != nil { + if err := srv.ImageDelete("utest:tag1"); err != nil { t.Fatal(err) }