github.com/jthurman42/docker@v1.6.0-rc1/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  	container, err := daemon.Get(name)
    17  	if err != nil {
    18  		return job.Error(err)
    19  	}
    20  
    21  	container.Lock()
    22  	defer container.Unlock()
    23  	if job.GetenvBool("raw") {
    24  		b, err := json.Marshal(&struct {
    25  			*Container
    26  			HostConfig *runconfig.HostConfig
    27  		}{container, container.hostConfig})
    28  		if err != nil {
    29  			return job.Error(err)
    30  		}
    31  		job.Stdout.Write(b)
    32  		return engine.StatusOK
    33  	}
    34  
    35  	out := &engine.Env{}
    36  	out.SetJson("Id", container.ID)
    37  	out.SetAuto("Created", container.Created)
    38  	out.SetJson("Path", container.Path)
    39  	out.SetList("Args", container.Args)
    40  	out.SetJson("Config", container.Config)
    41  	out.SetJson("State", container.State)
    42  	out.Set("Image", container.ImageID)
    43  	out.SetJson("NetworkSettings", container.NetworkSettings)
    44  	out.Set("ResolvConfPath", container.ResolvConfPath)
    45  	out.Set("HostnamePath", container.HostnamePath)
    46  	out.Set("HostsPath", container.HostsPath)
    47  	out.Set("LogPath", container.LogPath)
    48  	out.SetJson("Name", container.Name)
    49  	out.SetInt("RestartCount", container.RestartCount)
    50  	out.Set("Driver", container.Driver)
    51  	out.Set("ExecDriver", container.ExecDriver)
    52  	out.Set("MountLabel", container.MountLabel)
    53  	out.Set("ProcessLabel", container.ProcessLabel)
    54  	out.SetJson("Volumes", container.Volumes)
    55  	out.SetJson("VolumesRW", container.VolumesRW)
    56  	out.SetJson("AppArmorProfile", container.AppArmorProfile)
    57  
    58  	out.SetList("ExecIDs", container.GetExecIDs())
    59  
    60  	if children, err := daemon.Children(container.Name); err == nil {
    61  		for linkAlias, child := range children {
    62  			container.hostConfig.Links = append(container.hostConfig.Links, fmt.Sprintf("%s:%s", child.Name, linkAlias))
    63  		}
    64  	}
    65  	// we need this trick to preserve empty log driver, so
    66  	// container will use daemon defaults even if daemon change them
    67  	if container.hostConfig.LogConfig.Type == "" {
    68  		container.hostConfig.LogConfig = daemon.defaultLogConfig
    69  		defer func() {
    70  			container.hostConfig.LogConfig = runconfig.LogConfig{}
    71  		}()
    72  	}
    73  
    74  	out.SetJson("HostConfig", container.hostConfig)
    75  
    76  	container.hostConfig.Links = nil
    77  	if _, err := out.WriteTo(job.Stdout); err != nil {
    78  		return job.Error(err)
    79  	}
    80  	return engine.StatusOK
    81  }
    82  
    83  func (daemon *Daemon) ContainerExecInspect(job *engine.Job) engine.Status {
    84  	if len(job.Args) != 1 {
    85  		return job.Errorf("usage: %s ID", job.Name)
    86  	}
    87  	id := job.Args[0]
    88  	eConfig, err := daemon.getExecConfig(id)
    89  	if err != nil {
    90  		return job.Error(err)
    91  	}
    92  
    93  	b, err := json.Marshal(*eConfig)
    94  	if err != nil {
    95  		return job.Error(err)
    96  	}
    97  	job.Stdout.Write(b)
    98  	return engine.StatusOK
    99  }