2014-05-20 15:36:15 -04:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2014-06-25 18:24:14 -04:00
|
|
|
"fmt"
|
2014-05-20 15:36:15 -04:00
|
|
|
|
2014-07-24 18:19:50 -04:00
|
|
|
"github.com/docker/docker/engine"
|
|
|
|
"github.com/docker/docker/runconfig"
|
2014-05-20 15:36:15 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func (daemon *Daemon) ContainerInspect(job *engine.Job) engine.Status {
|
|
|
|
if len(job.Args) != 1 {
|
|
|
|
return job.Errorf("usage: %s NAME", job.Name)
|
|
|
|
}
|
|
|
|
name := job.Args[0]
|
|
|
|
if container := daemon.Get(name); container != nil {
|
2014-06-14 13:08:23 -04:00
|
|
|
container.Lock()
|
|
|
|
defer container.Unlock()
|
2014-06-16 20:06:21 -04:00
|
|
|
if job.GetenvBool("raw") {
|
2014-05-30 21:13:37 -04:00
|
|
|
b, err := json.Marshal(&struct {
|
|
|
|
*Container
|
|
|
|
HostConfig *runconfig.HostConfig
|
2014-06-14 13:08:23 -04:00
|
|
|
}{container, container.hostConfig})
|
2014-05-30 21:13:37 -04:00
|
|
|
if err != nil {
|
|
|
|
return job.Error(err)
|
|
|
|
}
|
|
|
|
job.Stdout.Write(b)
|
|
|
|
return engine.StatusOK
|
|
|
|
}
|
|
|
|
|
|
|
|
out := &engine.Env{}
|
2014-12-11 07:56:21 -05:00
|
|
|
out.SetJson("Id", container.ID)
|
2014-05-30 21:13:37 -04:00
|
|
|
out.SetAuto("Created", container.Created)
|
2014-09-15 19:35:07 -04:00
|
|
|
out.SetJson("Path", container.Path)
|
2014-05-30 21:13:37 -04:00
|
|
|
out.SetList("Args", container.Args)
|
|
|
|
out.SetJson("Config", container.Config)
|
|
|
|
out.SetJson("State", container.State)
|
2014-10-28 17:06:23 -04:00
|
|
|
out.Set("Image", container.ImageID)
|
2014-05-30 21:13:37 -04:00
|
|
|
out.SetJson("NetworkSettings", container.NetworkSettings)
|
|
|
|
out.Set("ResolvConfPath", container.ResolvConfPath)
|
|
|
|
out.Set("HostnamePath", container.HostnamePath)
|
|
|
|
out.Set("HostsPath", container.HostsPath)
|
2014-12-11 07:56:21 -05:00
|
|
|
out.SetJson("Name", container.Name)
|
2014-12-11 18:09:48 -05:00
|
|
|
out.SetInt("RestartCount", container.RestartCount)
|
2014-05-30 21:13:37 -04:00
|
|
|
out.Set("Driver", container.Driver)
|
|
|
|
out.Set("ExecDriver", container.ExecDriver)
|
|
|
|
out.Set("MountLabel", container.MountLabel)
|
|
|
|
out.Set("ProcessLabel", container.ProcessLabel)
|
2014-06-02 20:05:54 -04:00
|
|
|
out.SetJson("Volumes", container.Volumes)
|
2014-05-30 21:13:37 -04:00
|
|
|
out.SetJson("VolumesRW", container.VolumesRW)
|
2014-11-03 18:00:49 -05:00
|
|
|
out.SetJson("AppArmorProfile", container.AppArmorProfile)
|
2014-06-25 18:24:14 -04:00
|
|
|
|
2014-12-23 17:03:20 -05:00
|
|
|
out.SetList("ExecIDs", container.GetExecIDs())
|
|
|
|
|
2014-06-25 18:24:14 -04:00
|
|
|
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))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-30 21:13:37 -04:00
|
|
|
out.SetJson("HostConfig", container.hostConfig)
|
2014-06-25 18:24:14 -04:00
|
|
|
|
|
|
|
container.hostConfig.Links = nil
|
2014-05-30 21:13:37 -04:00
|
|
|
if _, err := out.WriteTo(job.Stdout); err != nil {
|
2014-05-20 15:36:15 -04:00
|
|
|
return job.Error(err)
|
|
|
|
}
|
|
|
|
return engine.StatusOK
|
|
|
|
}
|
|
|
|
return job.Errorf("No such container: %s", name)
|
|
|
|
}
|
2014-11-17 18:50:09 -05:00
|
|
|
|
|
|
|
func (daemon *Daemon) ContainerExecInspect(job *engine.Job) engine.Status {
|
|
|
|
if len(job.Args) != 1 {
|
|
|
|
return job.Errorf("usage: %s ID", job.Name)
|
|
|
|
}
|
|
|
|
id := job.Args[0]
|
|
|
|
eConfig, err := daemon.getExecConfig(id)
|
|
|
|
if err != nil {
|
|
|
|
return job.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
b, err := json.Marshal(*eConfig)
|
|
|
|
if err != nil {
|
|
|
|
return job.Error(err)
|
|
|
|
}
|
|
|
|
job.Stdout.Write(b)
|
|
|
|
return engine.StatusOK
|
|
|
|
}
|