зеркало из https://github.com/microsoft/docker.git
Merge pull request #9800 from vieux/execIDs_inspect
Add ExecIDs to docker inspect
This commit is contained in:
Коммит
12fef2d8df
|
@ -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()
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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": "",
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче