Skip to content

Commit

Permalink
Merge pull request moby#15023 from hqhq/hq_add_status_in_inspect
Browse files Browse the repository at this point in the history
Add status string to State field for inspect
  • Loading branch information
LK4D4 committed Aug 28, 2015
2 parents fdc73cc + fed85c3 commit 6caaa8a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
1 change: 1 addition & 0 deletions api/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ type ExecStartCheck struct {
// ContainerState stores container's running state
// it's part of ContainerJSONBase and will return by "inspect" command
type ContainerState struct {
Status string
Running bool
Paused bool
Restarting bool
Expand Down
1 change: 1 addition & 0 deletions daemon/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,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,
Expand Down
6 changes: 4 additions & 2 deletions docs/reference/api/docker_remote_api_v1.21.md
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,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": [
{
Expand Down Expand Up @@ -2176,6 +2177,7 @@ Return low-level information about the `exec` command `id`.
"OpenStdout" : false,
"Container" : {
"State" : {
"Status" : "running",
"Running" : true,
"Paused" : false,
"Restarting" : false,
Expand Down
32 changes: 32 additions & 0 deletions integration-cli/docker_cli_inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,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
Expand Down

0 comments on commit 6caaa8a

Please sign in to comment.