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
|
|
|
)
|
|
|
|
|
2015-03-25 03:44:12 -04:00
|
|
|
func (daemon *Daemon) ContainerInspect(job *engine.Job) error {
|
2014-05-20 15:36:15 -04:00
|
|
|
if len(job.Args) != 1 {
|
2015-03-25 03:44:12 -04:00
|
|
|
return fmt.Errorf("usage: %s NAME", job.Name)
|
2014-05-20 15:36:15 -04:00
|
|
|
}
|
|
|
|
name := job.Args[0]
|
2014-12-16 18:06:35 -05:00
|
|
|
container, err := daemon.Get(name)
|
|
|
|
if err != nil {
|
2015-03-25 03:44:12 -04:00
|
|
|
return err
|
2014-12-16 18:06:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
container.Lock()
|
|
|
|
defer container.Unlock()
|
|
|
|
if job.GetenvBool("raw") {
|
|
|
|
b, err := json.Marshal(&struct {
|
|
|
|
*Container
|
|
|
|
HostConfig *runconfig.HostConfig
|
|
|
|
}{container, container.hostConfig})
|
|
|
|
if err != nil {
|
2015-03-25 03:44:12 -04:00
|
|
|
return err
|
2014-05-30 21:13:37 -04:00
|
|
|
}
|
2014-12-16 18:06:35 -05:00
|
|
|
job.Stdout.Write(b)
|
2015-03-25 03:44:12 -04:00
|
|
|
return nil
|
2014-12-16 18:06:35 -05:00
|
|
|
}
|
2014-05-30 21:13:37 -04:00
|
|
|
|
2014-12-16 18:06:35 -05:00
|
|
|
out := &engine.Env{}
|
|
|
|
out.SetJson("Id", container.ID)
|
|
|
|
out.SetAuto("Created", container.Created)
|
|
|
|
out.SetJson("Path", container.Path)
|
|
|
|
out.SetList("Args", container.Args)
|
|
|
|
out.SetJson("Config", container.Config)
|
|
|
|
out.SetJson("State", container.State)
|
|
|
|
out.Set("Image", container.ImageID)
|
|
|
|
out.SetJson("NetworkSettings", container.NetworkSettings)
|
|
|
|
out.Set("ResolvConfPath", container.ResolvConfPath)
|
|
|
|
out.Set("HostnamePath", container.HostnamePath)
|
|
|
|
out.Set("HostsPath", container.HostsPath)
|
2015-02-06 12:25:42 -05:00
|
|
|
out.Set("LogPath", container.LogPath)
|
2014-12-16 18:06:35 -05:00
|
|
|
out.SetJson("Name", container.Name)
|
|
|
|
out.SetInt("RestartCount", container.RestartCount)
|
|
|
|
out.Set("Driver", container.Driver)
|
|
|
|
out.Set("ExecDriver", container.ExecDriver)
|
|
|
|
out.Set("MountLabel", container.MountLabel)
|
|
|
|
out.Set("ProcessLabel", container.ProcessLabel)
|
|
|
|
out.SetJson("Volumes", container.Volumes)
|
|
|
|
out.SetJson("VolumesRW", container.VolumesRW)
|
|
|
|
out.SetJson("AppArmorProfile", container.AppArmorProfile)
|
2014-06-25 18:24:14 -04:00
|
|
|
|
2014-12-16 18:06:35 -05:00
|
|
|
out.SetList("ExecIDs", container.GetExecIDs())
|
2014-12-23 17:03:20 -05:00
|
|
|
|
2014-12-16 18:06:35 -05: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-06-25 18:24:14 -04:00
|
|
|
}
|
2014-12-16 18:06:35 -05:00
|
|
|
}
|
2015-02-04 14:04:58 -05:00
|
|
|
// we need this trick to preserve empty log driver, so
|
|
|
|
// container will use daemon defaults even if daemon change them
|
|
|
|
if container.hostConfig.LogConfig.Type == "" {
|
|
|
|
container.hostConfig.LogConfig = daemon.defaultLogConfig
|
|
|
|
defer func() {
|
|
|
|
container.hostConfig.LogConfig = runconfig.LogConfig{}
|
|
|
|
}()
|
|
|
|
}
|
2014-06-25 18:24:14 -04:00
|
|
|
|
2014-12-16 18:06:35 -05:00
|
|
|
out.SetJson("HostConfig", container.hostConfig)
|
2014-06-25 18:24:14 -04:00
|
|
|
|
2014-12-16 18:06:35 -05:00
|
|
|
container.hostConfig.Links = nil
|
|
|
|
if _, err := out.WriteTo(job.Stdout); err != nil {
|
2015-03-25 03:44:12 -04:00
|
|
|
return err
|
2014-05-20 15:36:15 -04:00
|
|
|
}
|
2015-03-25 03:44:12 -04:00
|
|
|
return nil
|
2014-05-20 15:36:15 -04:00
|
|
|
}
|
2014-11-17 18:50:09 -05:00
|
|
|
|
2015-04-11 18:15:34 -04:00
|
|
|
func (daemon *Daemon) ContainerExecInspect(id string) (*execConfig, error) {
|
2014-11-17 18:50:09 -05:00
|
|
|
eConfig, err := daemon.getExecConfig(id)
|
|
|
|
if err != nil {
|
2015-04-11 18:15:34 -04:00
|
|
|
return nil, err
|
2014-11-17 18:50:09 -05:00
|
|
|
}
|
|
|
|
|
2015-04-11 18:15:34 -04:00
|
|
|
return eConfig, nil
|
2014-11-17 18:50:09 -05:00
|
|
|
}
|