utils.go 647 B

12345678910111213141516171819202122
  1. package container
  2. import (
  3. "golang.org/x/net/context"
  4. "github.com/docker/docker/api/client"
  5. clientapi "github.com/docker/engine-api/client"
  6. )
  7. // getExitCode perform an inspect on the container. It returns
  8. // the running state and the exit code.
  9. func getExitCode(dockerCli *client.DockerCli, ctx context.Context, containerID string) (bool, int, error) {
  10. c, err := dockerCli.Client().ContainerInspect(ctx, containerID)
  11. if err != nil {
  12. // If we can't connect, then the daemon probably died.
  13. if err != clientapi.ErrConnectionFailed {
  14. return false, -1, err
  15. }
  16. return false, -1, nil
  17. }
  18. return c.State.Running, c.State.ExitCode, nil
  19. }