state.go#Action

  1. Action: func(context *cli.Context) error {
  2. if err := checkArgs(context, 1, exactArgs); err != nil {
  3. return err
  4. }
  5. container, err := getContainer(context)
  6. if err != nil {
  7. return err
  8. }
  9. containerStatus, err := container.Status()
  10. if err != nil {
  11. return err
  12. }
  13. state, err := container.State()
  14. if err != nil {
  15. return err
  16. }
  17. pid := state.BaseState.InitProcessPid
  18. if containerStatus == libcontainer.Stopped {
  19. pid = 0
  20. }
  21. bundle, annotations := utils.Annotations(state.Config.Labels)
  22. cs := containerState{
  23. Version: state.BaseState.Config.Version,
  24. ID: state.BaseState.ID,
  25. InitProcessPid: pid,
  26. Status: containerStatus.String(),
  27. Bundle: bundle,
  28. Rootfs: state.BaseState.Config.Rootfs,
  29. Created: state.BaseState.Created,
  30. Annotations: annotations,
  31. }
  32. data, err := json.MarshalIndent(cs, "", " ")
  33. if err != nil {
  34. return err
  35. }
  36. os.Stdout.Write(data)
  37. return nil
  38. },
  1. // containerState represents the platform agnostic pieces relating to a
  2. // running container's status and state
  3. type containerState struct {
  4. // Version is the OCI version for the container
  5. Version string `json:"ociVersion"`
  6. // ID is the container ID
  7. ID string `json:"id"`
  8. // InitProcessPid is the init process id in the parent namespace
  9. InitProcessPid int `json:"pid"`
  10. // Status is the current status of the container, running, paused, ...
  11. Status string `json:"status"`
  12. // Bundle is the path on the filesystem to the bundle
  13. Bundle string `json:"bundle"`
  14. // Rootfs is a path to a directory containing the container's root filesystem.
  15. Rootfs string `json:"rootfs"`
  16. // Created is the unix timestamp for the creation time of the container in UTC
  17. Created time.Time `json:"created"`
  18. // Annotations is the user defined annotations added to the config.
  19. Annotations map[string]string `json:"annotations,omitempty"`
  20. // The owner of the state directory (the owner of the container).
  21. Owner string `json:"owner"`
  22. }