rm.go 1.1 KB

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