github.com/guilhermebr/docker@v1.4.2-0.20150428121140-67da055cebca/api/client/rm.go (about) 1 package client 2 3 import ( 4 "fmt" 5 "net/url" 6 7 flag "github.com/docker/docker/pkg/mflag" 8 ) 9 10 // CmdRm removes one or more containers. 11 // 12 // Usage: docker rm [OPTIONS] CONTAINER [CONTAINER...] 13 func (cli *DockerCli) CmdRm(args ...string) error { 14 cmd := cli.Subcmd("rm", "CONTAINER [CONTAINER...]", "Remove one or more containers", true) 15 v := cmd.Bool([]string{"v", "-volumes"}, false, "Remove the volumes associated with the container") 16 link := cmd.Bool([]string{"l", "#link", "-link"}, false, "Remove the specified link") 17 force := cmd.Bool([]string{"f", "-force"}, false, "Force the removal of a running container (uses SIGKILL)") 18 cmd.Require(flag.Min, 1) 19 20 cmd.ParseFlags(args, true) 21 22 val := url.Values{} 23 if *v { 24 val.Set("v", "1") 25 } 26 if *link { 27 val.Set("link", "1") 28 } 29 30 if *force { 31 val.Set("force", "1") 32 } 33 34 var encounteredError error 35 for _, name := range cmd.Args() { 36 if name == "" { 37 return fmt.Errorf("Container name cannot be empty") 38 } 39 40 _, _, err := readBody(cli.call("DELETE", "/containers/"+name+"?"+val.Encode(), nil, nil)) 41 if err != nil { 42 fmt.Fprintf(cli.err, "%s\n", err) 43 encounteredError = fmt.Errorf("Error: failed to remove one or more containers") 44 } else { 45 fmt.Fprintf(cli.out, "%s\n", name) 46 } 47 } 48 return encounteredError 49 }