Skip to content

Commit

Permalink
Merge pull request moby#9800 from vieux/execIDs_inspect
Browse files Browse the repository at this point in the history
Add ExecIDs to docker inspect
  • Loading branch information
LK4D4 committed Dec 29, 2014
2 parents d47020d + c0bb1c7 commit 12fef2d
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 3 deletions.
20 changes: 17 additions & 3 deletions daemon/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type execConfig struct {

type execStore struct {
s map[string]*execConfig
sync.Mutex
sync.RWMutex
}

func newExecStore() *execStore {
Expand All @@ -49,9 +49,9 @@ func (e *execStore) Add(id string, execConfig *execConfig) {
}

func (e *execStore) Get(id string) *execConfig {
e.Lock()
e.RLock()
res := e.s[id]
e.Unlock()
e.RUnlock()
return res
}

Expand All @@ -61,6 +61,16 @@ func (e *execStore) Delete(id string) {
e.Unlock()
}

func (e *execStore) List() []string {
var IDs []string
e.RLock()
for id := range e.s {
IDs = append(IDs, id)
}
e.RUnlock()
return IDs
}

func (execConfig *execConfig) Resize(h, w int) error {
return execConfig.ProcessConfig.Terminal.Resize(h, w)
}
Expand Down Expand Up @@ -249,6 +259,10 @@ func (d *Daemon) Exec(c *Container, execConfig *execConfig, pipes *execdriver.Pi
return exitStatus, err
}

func (container *Container) GetExecIDs() []string {
return container.execCommands.List()
}

func (container *Container) Exec(execConfig *execConfig) error {
container.Lock()
defer container.Unlock()
Expand Down
2 changes: 2 additions & 0 deletions daemon/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ func (daemon *Daemon) ContainerInspect(job *engine.Job) engine.Status {
out.SetJson("VolumesRW", container.VolumesRW)
out.SetJson("AppArmorProfile", container.AppArmorProfile)

out.SetList("ExecIDs", container.GetExecIDs())

if children, err := daemon.Children(container.Name); err == nil {
for linkAlias, child := range children {
container.hostConfig.Links = append(container.hostConfig.Links, fmt.Sprintf("%s:%s", child.Name, linkAlias))
Expand Down
5 changes: 5 additions & 0 deletions docs/sources/reference/api/docker_remote_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ You can still call an old version of the API using
**New!**
Docker client now hints potential proxies about connection hijacking using HTTP Upgrade headers.

`GET /containers/(id)/json`

**New!**
This endpoint now returns the list current execs associated with the container (`ExecIDs`).

## v1.16

### Full Documentation
Expand Down
3 changes: 3 additions & 0 deletions docs/sources/reference/api/docker_remote_api_v1.17.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@ Return low-level information on the container `id`
"SysInitPath": "/home/kitty/go/src/github.com/docker/docker/bin/docker",
"ResolvConfPath": "/etc/resolv.conf",
"Volumes": {},
"ExecIDs": [
"15f211491dced6a353a2e0f37fe3f3692ee2370a4782418e9bf7052865c10fde"
],
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
Expand Down
35 changes: 35 additions & 0 deletions integration-cli/docker_cli_inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,38 @@ func TestInspectImage(t *testing.T) {

logDone("inspect - inspect an image")
}

func TestInspectExecID(t *testing.T) {
defer deleteAllContainers()

out, exitCode, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "busybox", "top"))
if exitCode != 0 || err != nil {
t.Fatalf("failed to run container: %s, %v", out, err)
}
id := strings.TrimSuffix(out, "\n")

out, err = inspectField(id, "ExecIDs")
if err != nil {
t.Fatalf("failed to inspect container: %s, %v", out, err)
}
if out != "<no value>" {
t.Fatalf("ExecIDs should be empty, got: %s", out)
}

exitCode, err = runCommand(exec.Command(dockerBinary, "exec", "-d", id, "ls", "/"))
if exitCode != 0 || err != nil {
t.Fatalf("failed to exec in container: %s, %v", out, err)
}

out, err = inspectField(id, "ExecIDs")
if err != nil {
t.Fatalf("failed to inspect container: %s, %v", out, err)
}

out = strings.TrimSuffix(out, "\n")
if out == "[]" || out == "<no value>" {
t.Fatalf("ExecIDs should not be empty, got: %s", out)
}

logDone("inspect - inspect a container with ExecIDs")
}

0 comments on commit 12fef2d

Please sign in to comment.