From 2a769cedb6bd8847e9885a41e0306f86091411b0 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Tue, 23 Dec 2014 22:03:20 +0000 Subject: [PATCH 1/3] add ExecIDs in inspect Signed-off-by: Victor Vieux Upstream-commit: 4b43a6df7acd98228b8b287eedf38ba87dc8a388 Component: engine --- components/engine/daemon/exec.go | 20 +++++++++++++++++--- components/engine/daemon/inspect.go | 2 ++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/components/engine/daemon/exec.go b/components/engine/daemon/exec.go index ecdbc58d85..92f23f7380 100644 --- a/components/engine/daemon/exec.go +++ b/components/engine/daemon/exec.go @@ -35,7 +35,7 @@ type execConfig struct { type execStore struct { s map[string]*execConfig - sync.Mutex + sync.RWMutex } func newExecStore() *execStore { @@ -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 } @@ -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) } @@ -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() diff --git a/components/engine/daemon/inspect.go b/components/engine/daemon/inspect.go index 2bf1773d3a..37d00573bc 100644 --- a/components/engine/daemon/inspect.go +++ b/components/engine/daemon/inspect.go @@ -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)) From 055349b7c92d5c411d7ccd78f86244d069918c65 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Wed, 24 Dec 2014 00:03:24 +0000 Subject: [PATCH 2/3] add docs Signed-off-by: Victor Vieux Upstream-commit: bbb92e1436b5a288d07ef8ea0fad80f2c4715faa Component: engine --- components/engine/daemon/exec.go | 2 +- .../engine/docs/sources/reference/api/docker_remote_api.md | 5 +++++ .../docs/sources/reference/api/docker_remote_api_v1.17.md | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/components/engine/daemon/exec.go b/components/engine/daemon/exec.go index 92f23f7380..616093c67d 100644 --- a/components/engine/daemon/exec.go +++ b/components/engine/daemon/exec.go @@ -64,7 +64,7 @@ func (e *execStore) Delete(id string) { func (e *execStore) List() []string { var IDs []string e.RLock() - for id, _ := range e.s { + for id := range e.s { IDs = append(IDs, id) } e.RUnlock() diff --git a/components/engine/docs/sources/reference/api/docker_remote_api.md b/components/engine/docs/sources/reference/api/docker_remote_api.md index e44576cea0..fa210d4583 100644 --- a/components/engine/docs/sources/reference/api/docker_remote_api.md +++ b/components/engine/docs/sources/reference/api/docker_remote_api.md @@ -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 diff --git a/components/engine/docs/sources/reference/api/docker_remote_api_v1.17.md b/components/engine/docs/sources/reference/api/docker_remote_api_v1.17.md index 6c544c96bb..772ba116e1 100644 --- a/components/engine/docs/sources/reference/api/docker_remote_api_v1.17.md +++ b/components/engine/docs/sources/reference/api/docker_remote_api_v1.17.md @@ -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": "", From 2156fea332eeb6932be4cacb4eeaaf588cff3dcd Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Sat, 27 Dec 2014 02:38:46 +0000 Subject: [PATCH 3/3] add test Signed-off-by: Victor Vieux Upstream-commit: c0bb1c77ee2461f8bceb03202f60f5673815c026 Component: engine --- .../docker_cli_inspect_test.go | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/components/engine/integration-cli/docker_cli_inspect_test.go b/components/engine/integration-cli/docker_cli_inspect_test.go index cf42217ac8..ee69a89a43 100644 --- a/components/engine/integration-cli/docker_cli_inspect_test.go +++ b/components/engine/integration-cli/docker_cli_inspect_test.go @@ -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 != "" { + 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 == "" { + t.Fatalf("ExecIDs should not be empty, got: %s", out) + } + + logDone("inspect - inspect a container with ExecIDs") +}