delete.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package runc
  2. import (
  3. "os"
  4. "path/filepath"
  5. "github.com/codegangsta/cli"
  6. "github.com/opencontainers/runc/libcontainer"
  7. )
  8. var deleteCommand = cli.Command{
  9. Name: "delete",
  10. Usage: "delete any resources held by the container often used with detached containers",
  11. ArgsUsage: `<container-id>
  12. Where "<container-id>" is the name for the instance of the container.
  13. For example, if the container id is "ubuntu01" and runc list currently shows the
  14. status of "ubuntu01" as "destroyed" the following will delete resources held for
  15. "ubuntu01" removing "ubuntu01" from the runc list of containers:
  16. # runc delete ubuntu01`,
  17. Action: func(context *cli.Context) {
  18. container, err := getContainer(context)
  19. if err != nil {
  20. if lerr, ok := err.(libcontainer.Error); ok && lerr.Code() == libcontainer.ContainerNotExists {
  21. // if there was an aborted start or something of the sort then the container's directory could exist but
  22. // libcontainer does not see it because the state.json file inside that directory was never created.
  23. path := filepath.Join(context.GlobalString("root"), context.Args().First())
  24. if err := os.RemoveAll(path); err == nil {
  25. return
  26. }
  27. }
  28. fatal(err)
  29. }
  30. destroy(container)
  31. },
  32. }