diff --git a/api/types/types.go b/api/types/types.go index c99e5a9a45..ed7b101508 100644 --- a/api/types/types.go +++ b/api/types/types.go @@ -207,6 +207,7 @@ type ExecStartCheck struct { } type ContainerState struct { + Status string Running bool Paused bool Restarting bool diff --git a/daemon/inspect.go b/daemon/inspect.go index df909e1854..3a280fd1fb 100644 --- a/daemon/inspect.go +++ b/daemon/inspect.go @@ -42,6 +42,7 @@ func (daemon *Daemon) getInspectData(container *Container) (*types.ContainerJSON } containerState := &types.ContainerState{ + Status: container.State.StateString(), Running: container.State.Running, Paused: container.State.Paused, Restarting: container.State.Restarting, diff --git a/docs/reference/api/docker_remote_api_v1.21.md b/docs/reference/api/docker_remote_api_v1.21.md index 802708265f..be69cbdcc4 100644 --- a/docs/reference/api/docker_remote_api_v1.21.md +++ b/docs/reference/api/docker_remote_api_v1.21.md @@ -425,8 +425,9 @@ Return low-level information on the container `id` "Paused": false, "Pid": 0, "Restarting": false, - "Running": false, - "StartedAt": "2015-01-06T15:47:32.072697474Z" + "Running": true, + "StartedAt": "2015-01-06T15:47:32.072697474Z", + "Status": "running" }, "Mounts": [ { @@ -2159,6 +2160,7 @@ Return low-level information about the `exec` command `id`. "OpenStdout" : false, "Container" : { "State" : { + "Status" : "running", "Running" : true, "Paused" : false, "Restarting" : false, diff --git a/integration-cli/docker_cli_inspect_test.go b/integration-cli/docker_cli_inspect_test.go index 1d5b7a6d42..95474eb4fe 100644 --- a/integration-cli/docker_cli_inspect_test.go +++ b/integration-cli/docker_cli_inspect_test.go @@ -47,6 +47,38 @@ func (s *DockerSuite) TestInspectDefault(c *check.C) { dockerCmd(c, "inspect", "busybox") } +func (s *DockerSuite) TestInspectStatus(c *check.C) { + out, _ := dockerCmd(c, "run", "-d", "busybox", "top") + out = strings.TrimSpace(out) + + inspectOut, err := inspectField(out, "State.Status") + c.Assert(err, check.IsNil) + if inspectOut != "running" { + c.Fatalf("inspect got wrong status, got: %q, expected: running", inspectOut) + } + + dockerCmd(c, "pause", out) + inspectOut, err = inspectField(out, "State.Status") + c.Assert(err, check.IsNil) + if inspectOut != "paused" { + c.Fatalf("inspect got wrong status, got: %q, expected: paused", inspectOut) + } + + dockerCmd(c, "unpause", out) + inspectOut, err = inspectField(out, "State.Status") + c.Assert(err, check.IsNil) + if inspectOut != "running" { + c.Fatalf("inspect got wrong status, got: %q, expected: running", inspectOut) + } + + dockerCmd(c, "stop", out) + inspectOut, err = inspectField(out, "State.Status") + c.Assert(err, check.IsNil) + if inspectOut != "exited" { + c.Fatalf("inspect got wrong status, got: %q, expected: exited", inspectOut) + } +} + func (s *DockerSuite) TestInspectTypeFlagContainer(c *check.C) { //Both the container and image are named busybox. docker inspect will fetch container