2014-05-20 19:36:15 +00:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2014-06-25 22:24:14 +00:00
|
|
|
"fmt"
|
2014-05-20 19:36:15 +00:00
|
|
|
|
2014-07-24 22:19:50 +00:00
|
|
|
"github.com/docker/docker/engine"
|
|
|
|
"github.com/docker/docker/runconfig"
|
2014-05-20 19:36:15 +00: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 17:08:23 +00:00
|
|
|
container.Lock()
|
|
|
|
defer container.Unlock()
|
2014-06-17 00:06:21 +00:00
|
|
|
if job.GetenvBool("raw") {
|
2014-05-31 01:13:37 +00:00
|
|
|
b, err := json.Marshal(&struct {
|
|
|
|
*Container
|
|
|
|
HostConfig *runconfig.HostConfig
|
2014-06-14 17:08:23 +00:00
|
|
|
}{container, container.hostConfig})
|
2014-05-31 01:13:37 +00:00
|
|
|
if err != nil {
|
|
|
|
return job.Error(err)
|
|
|
|
}
|
|
|
|
job.Stdout.Write(b)
|
|
|
|
return engine.StatusOK
|
|
|
|
}
|
|
|
|
|
|
|
|
out := &engine.Env{}
|
|
|
|
out.Set("Id", container.ID)
|
|
|
|
out.SetAuto("Created", container.Created)
|
2014-09-15 23:35:07 +00:00
|
|
|
out.SetJson("Path", container.Path)
|
2014-05-31 01:13:37 +00:00
|
|
|
out.SetList("Args", container.Args)
|
|
|
|
out.SetJson("Config", container.Config)
|
|
|
|
out.SetJson("State", container.State)
|
|
|
|
out.Set("Image", container.Image)
|
|
|
|
out.SetJson("NetworkSettings", container.NetworkSettings)
|
|
|
|
out.Set("ResolvConfPath", container.ResolvConfPath)
|
|
|
|
out.Set("HostnamePath", container.HostnamePath)
|
|
|
|
out.Set("HostsPath", container.HostsPath)
|
|
|
|
out.Set("Name", container.Name)
|
|
|
|
out.Set("Driver", container.Driver)
|
|
|
|
out.Set("ExecDriver", container.ExecDriver)
|
|
|
|
out.Set("MountLabel", container.MountLabel)
|
|
|
|
out.Set("ProcessLabel", container.ProcessLabel)
|
2014-06-03 00:05:54 +00:00
|
|
|
out.SetJson("Volumes", container.Volumes)
|
2014-05-31 01:13:37 +00:00
|
|
|
out.SetJson("VolumesRW", container.VolumesRW)
|
2014-06-25 22:24:14 +00: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-31 01:13:37 +00:00
|
|
|
out.SetJson("HostConfig", container.hostConfig)
|
2014-06-25 22:24:14 +00:00
|
|
|
|
|
|
|
container.hostConfig.Links = nil
|
2014-05-31 01:13:37 +00:00
|
|
|
if _, err := out.WriteTo(job.Stdout); err != nil {
|
2014-05-20 19:36:15 +00:00
|
|
|
return job.Error(err)
|
|
|
|
}
|
|
|
|
return engine.StatusOK
|
|
|
|
}
|
|
|
|
return job.Errorf("No such container: %s", name)
|
|
|
|
}
|