2014-05-20 15:36:15 -04:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
2014-06-25 18:24:14 -04:00
|
|
|
"fmt"
|
2014-05-20 15:36:15 -04:00
|
|
|
|
2015-04-13 10:17:14 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
2014-05-20 15:36:15 -04:00
|
|
|
)
|
|
|
|
|
2015-04-13 10:17:14 -04:00
|
|
|
func (daemon *Daemon) ContainerInspect(name string) (*types.ContainerJSON, error) {
|
|
|
|
container, err := daemon.Get(name)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2014-12-16 18:06:35 -05:00
|
|
|
}
|
2014-05-30 21:13:37 -04:00
|
|
|
|
2015-04-13 10:17:14 -04:00
|
|
|
container.Lock()
|
|
|
|
defer container.Unlock()
|
2014-06-25 18:24:14 -04:00
|
|
|
|
2015-06-02 17:37:59 -04:00
|
|
|
base, err := daemon.getInspectData(container)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2015-06-03 15:21:38 -04:00
|
|
|
mountPoints := make([]types.MountPoint, 0, len(container.MountPoints))
|
|
|
|
for _, m := range container.MountPoints {
|
|
|
|
mountPoints = append(mountPoints, types.MountPoint{
|
|
|
|
Name: m.Name,
|
|
|
|
Source: m.Path(),
|
|
|
|
Destination: m.Destination,
|
|
|
|
Driver: m.Driver,
|
|
|
|
Mode: m.Relabel,
|
|
|
|
RW: m.RW,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return &types.ContainerJSON{base, mountPoints, container.Config}, nil
|
2015-06-02 17:37:59 -04:00
|
|
|
}
|
|
|
|
|
2015-06-03 15:21:38 -04:00
|
|
|
func (daemon *Daemon) ContainerInspectPre120(name string) (*types.ContainerJSONPre120, error) {
|
2015-06-02 17:37:59 -04:00
|
|
|
container, err := daemon.Get(name)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
container.Lock()
|
|
|
|
defer container.Unlock()
|
|
|
|
|
|
|
|
base, err := daemon.getInspectData(container)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2015-06-03 15:21:38 -04:00
|
|
|
volumes := make(map[string]string)
|
|
|
|
volumesRW := make(map[string]bool)
|
|
|
|
for _, m := range container.MountPoints {
|
|
|
|
volumes[m.Destination] = m.Path()
|
|
|
|
volumesRW[m.Destination] = m.RW
|
|
|
|
}
|
|
|
|
|
2015-06-02 17:37:59 -04:00
|
|
|
config := &types.ContainerConfig{
|
|
|
|
container.Config,
|
|
|
|
container.hostConfig.Memory,
|
|
|
|
container.hostConfig.MemorySwap,
|
|
|
|
container.hostConfig.CpuShares,
|
|
|
|
container.hostConfig.CpusetCpus,
|
|
|
|
}
|
|
|
|
|
2015-06-03 15:21:38 -04:00
|
|
|
return &types.ContainerJSONPre120{base, volumes, volumesRW, config}, nil
|
2015-06-02 17:37:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (daemon *Daemon) getInspectData(container *Container) (*types.ContainerJSONBase, error) {
|
2015-04-13 10:17:14 -04:00
|
|
|
// make a copy to play with
|
|
|
|
hostConfig := *container.hostConfig
|
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 {
|
2015-04-13 10:17:14 -04:00
|
|
|
hostConfig.Links = append(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
|
2015-04-13 10:17:14 -04:00
|
|
|
if hostConfig.LogConfig.Type == "" {
|
|
|
|
hostConfig.LogConfig = daemon.defaultLogConfig
|
2015-02-04 14:04:58 -05:00
|
|
|
}
|
2014-06-25 18:24:14 -04:00
|
|
|
|
2015-04-13 10:17:14 -04:00
|
|
|
containerState := &types.ContainerState{
|
|
|
|
Running: container.State.Running,
|
|
|
|
Paused: container.State.Paused,
|
|
|
|
Restarting: container.State.Restarting,
|
|
|
|
OOMKilled: container.State.OOMKilled,
|
|
|
|
Dead: container.State.Dead,
|
|
|
|
Pid: container.State.Pid,
|
|
|
|
ExitCode: container.State.ExitCode,
|
|
|
|
Error: container.State.Error,
|
|
|
|
StartedAt: container.State.StartedAt,
|
|
|
|
FinishedAt: container.State.FinishedAt,
|
|
|
|
}
|
2014-06-25 18:24:14 -04:00
|
|
|
|
2015-06-02 17:37:59 -04:00
|
|
|
contJSONBase := &types.ContainerJSONBase{
|
2015-04-13 10:17:14 -04:00
|
|
|
Id: container.ID,
|
|
|
|
Created: container.Created,
|
|
|
|
Path: container.Path,
|
|
|
|
Args: container.Args,
|
|
|
|
State: containerState,
|
|
|
|
Image: container.ImageID,
|
|
|
|
NetworkSettings: container.NetworkSettings,
|
|
|
|
ResolvConfPath: container.ResolvConfPath,
|
|
|
|
HostnamePath: container.HostnamePath,
|
|
|
|
HostsPath: container.HostsPath,
|
|
|
|
LogPath: container.LogPath,
|
|
|
|
Name: container.Name,
|
|
|
|
RestartCount: container.RestartCount,
|
|
|
|
Driver: container.Driver,
|
|
|
|
ExecDriver: container.ExecDriver,
|
|
|
|
MountLabel: container.MountLabel,
|
|
|
|
ProcessLabel: container.ProcessLabel,
|
|
|
|
AppArmorProfile: container.AppArmorProfile,
|
|
|
|
ExecIDs: container.GetExecIDs(),
|
|
|
|
HostConfig: &hostConfig,
|
2014-05-20 15:36:15 -04:00
|
|
|
}
|
2015-04-13 10:17:14 -04:00
|
|
|
|
2015-06-15 14:05:10 -04:00
|
|
|
contJSONBase.GraphDriver.Name = container.Driver
|
|
|
|
graphDriverData, err := daemon.driver.GetMetadata(container.ID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
contJSONBase.GraphDriver.Data = graphDriverData
|
|
|
|
|
2015-06-02 17:37:59 -04:00
|
|
|
return contJSONBase, 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
|
|
|
}
|