rm.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. if name == "" {
  27. return fmt.Errorf("Container name cannot be empty")
  28. }
  29. _, _, err := readBody(cli.call("DELETE", "/containers/"+name+"?"+val.Encode(), nil, nil))
  30. if err != nil {
  31. fmt.Fprintf(cli.err, "%s\n", err)
  32. encounteredError = fmt.Errorf("Error: failed to remove one or more containers")
  33. } else {
  34. fmt.Fprintf(cli.out, "%s\n", name)
  35. }
  36. }
  37. return encounteredError
  38. }