github.com/eikeon/docker@v1.5.0-rc4/daemon/inspect.go (about)

     1  package daemon
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  
     7  	"github.com/docker/docker/engine"
     8  	"github.com/docker/docker/runconfig"
     9  )
    10  
    11  func (daemon *Daemon) ContainerInspect(job *engine.Job) engine.Status {
    12  	if len(job.Args) != 1 {
    13  		return job.Errorf("usage: %s NAME", job.Name)
    14  	}
    15  	name := job.Args[0]
    16  	if container := daemon.Get(name); container != nil {
    17  		container.Lock()
    18  		defer container.Unlock()
    19  		if job.GetenvBool("raw") {
    20  			b, err := json.Marshal(&struct {
    21  				*Container
    22  				HostConfig *runconfig.HostConfig
    23  			}{container, container.hostConfig})
    24  			if err != nil {
    25  				return job.Error(err)
    26  			}
    27  			job.Stdout.Write(b)
    28  			return engine.StatusOK
    29  		}
    30  
    31  		out := &engine.Env{}
    32  		out.SetJson("Id", container.ID)
    33  		out.SetAuto("Created", container.Created)
    34  		out.SetJson("Path", container.Path)
    35  		out.SetList("Args", container.Args)
    36  		out.SetJson("Config", container.Config)
    37  		out.SetJson("State", container.State)
    38  		out.Set("Image", container.ImageID)
    39  		out.SetJson("NetworkSettings", container.NetworkSettings)
    40  		out.Set("ResolvConfPath", container.ResolvConfPath)
    41  		out.Set("HostnamePath", container.HostnamePath)
    42  		out.Set("HostsPath", container.HostsPath)
    43  		out.SetJson("Name", container.Name)
    44  		out.SetInt("RestartCount", container.RestartCount)
    45  		out.Set("Driver", container.Driver)
    46  		out.Set("ExecDriver", container.ExecDriver)
    47  		out.Set("MountLabel", container.MountLabel)
    48  		out.Set("ProcessLabel", container.ProcessLabel)
    49  		out.SetJson("Volumes", container.Volumes)
    50  		out.SetJson("VolumesRW", container.VolumesRW)
    51  		out.SetJson("AppArmorProfile", container.AppArmorProfile)
    52  
    53  		out.SetList("ExecIDs", container.GetExecIDs())
    54  
    55  		if children, err := daemon.Children(container.Name); err == nil {
    56  			for linkAlias, child := range children {
    57  				container.hostConfig.Links = append(container.hostConfig.Links, fmt.Sprintf("%s:%s", child.Name, linkAlias))
    58  			}
    59  		}
    60  
    61  		out.SetJson("HostConfig", container.hostConfig)
    62  
    63  		container.hostConfig.Links = nil
    64  		if _, err := out.WriteTo(job.Stdout); err != nil {
    65  			return job.Error(err)
    66  		}
    67  		return engine.StatusOK
    68  	}
    69  	return job.Errorf("No such container: %s", name)
    70  }
    71  
    72  func (daemon *Daemon) ContainerExecInspect(job *engine.Job) engine.Status {
    73  	if len(job.Args) != 1 {
    74  		return job.Errorf("usage: %s ID", job.Name)
    75  	}
    76  	id := job.Args[0]
    77  	eConfig, err := daemon.getExecConfig(id)
    78  	if err != nil {
    79  		return job.Error(err)
    80  	}
    81  
    82  	b, err := json.Marshal(*eConfig)
    83  	if err != nil {
    84  		return job.Error(err)
    85  	}
    86  	job.Stdout.Write(b)
    87  	return engine.StatusOK
    88  }