mirror of
https://github.com/docker/docs.git
synced 2026-03-27 14:28:47 +07:00
Signed-off-by: allencloud <allen.sun@daocloud.io> (cherry picked from commit 4e959ef2f7f063803d04e06166f459257eb94b5c) Signed-off-by: Tibor Vass <tibor@docker.com>
23 lines
648 B
Go
23 lines
648 B
Go
package container
|
|
|
|
import (
|
|
"golang.org/x/net/context"
|
|
|
|
"github.com/docker/docker/api/client"
|
|
clientapi "github.com/docker/engine-api/client"
|
|
)
|
|
|
|
// getExitCode performs an inspect on the container. It returns
|
|
// the running state and the exit code.
|
|
func getExitCode(dockerCli *client.DockerCli, ctx context.Context, containerID string) (bool, int, error) {
|
|
c, err := dockerCli.Client().ContainerInspect(ctx, containerID)
|
|
if err != nil {
|
|
// If we can't connect, then the daemon probably died.
|
|
if err != clientapi.ErrConnectionFailed {
|
|
return false, -1, err
|
|
}
|
|
return false, -1, nil
|
|
}
|
|
return c.State.Running, c.State.ExitCode, nil
|
|
}
|