github.com/ncdc/docker@v0.10.1-0.20160129113957-6c6729ef5b74/api/client/rmi.go (about) 1 package client 2 3 import ( 4 "fmt" 5 "net/url" 6 "strings" 7 8 Cli "github.com/docker/docker/cli" 9 flag "github.com/docker/docker/pkg/mflag" 10 "github.com/docker/engine-api/types" 11 ) 12 13 // CmdRmi removes all images with the specified name(s). 14 // 15 // Usage: docker rmi [OPTIONS] IMAGE [IMAGE...] 16 func (cli *DockerCli) CmdRmi(args ...string) error { 17 cmd := Cli.Subcmd("rmi", []string{"IMAGE [IMAGE...]"}, Cli.DockerCommands["rmi"].Description, true) 18 force := cmd.Bool([]string{"f", "-force"}, false, "Force removal of the image") 19 noprune := cmd.Bool([]string{"-no-prune"}, false, "Do not delete untagged parents") 20 cmd.Require(flag.Min, 1) 21 22 cmd.ParseFlags(args, true) 23 24 v := url.Values{} 25 if *force { 26 v.Set("force", "1") 27 } 28 if *noprune { 29 v.Set("noprune", "1") 30 } 31 32 var errs []string 33 for _, name := range cmd.Args() { 34 options := types.ImageRemoveOptions{ 35 ImageID: name, 36 Force: *force, 37 PruneChildren: !*noprune, 38 } 39 40 dels, err := cli.client.ImageRemove(options) 41 if err != nil { 42 errs = append(errs, fmt.Sprintf("Failed to remove image (%s): %s", name, err)) 43 } else { 44 for _, del := range dels { 45 if del.Deleted != "" { 46 fmt.Fprintf(cli.out, "Deleted: %s\n", del.Deleted) 47 } else { 48 fmt.Fprintf(cli.out, "Untagged: %s\n", del.Untagged) 49 } 50 } 51 } 52 } 53 if len(errs) > 0 { 54 return fmt.Errorf("%s", strings.Join(errs, "\n")) 55 } 56 return nil 57 }