2014-05-20 19:36:15 +00:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
2014-06-25 22:24:14 +00:00
|
|
|
"fmt"
|
2014-05-20 19:36:15 +00:00
|
|
|
|
2015-04-13 14:17:14 +00:00
|
|
|
"github.com/docker/docker/api/types"
|
2014-07-24 22:19:50 +00:00
|
|
|
"github.com/docker/docker/runconfig"
|
2014-05-20 19:36:15 +00:00
|
|
|
)
|
|
|
|
|
2015-04-13 14:17:14 +00:00
|
|
|
type ContainerJSONRaw struct {
|
|
|
|
*Container
|
|
|
|
HostConfig *runconfig.HostConfig
|
|
|
|
}
|
|
|
|
|
|
|
|
func (daemon *Daemon) ContainerInspectRaw(name string) (*ContainerJSONRaw, error) {
|
2014-12-16 23:06:35 +00:00
|
|
|
container, err := daemon.Get(name)
|
|
|
|
if err != nil {
|
2015-04-13 14:17:14 +00:00
|
|
|
return nil, err
|
2014-12-16 23:06:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
container.Lock()
|
|
|
|
defer container.Unlock()
|
2015-04-13 14:17:14 +00:00
|
|
|
|
|
|
|
return &ContainerJSONRaw{container, container.hostConfig}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (daemon *Daemon) ContainerInspect(name string) (*types.ContainerJSON, error) {
|
|
|
|
container, err := daemon.Get(name)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2014-12-16 23:06:35 +00:00
|
|
|
}
|
2014-05-31 01:13:37 +00:00
|
|
|
|
2015-04-13 14:17:14 +00:00
|
|
|
container.Lock()
|
|
|
|
defer container.Unlock()
|
2014-06-25 22:24:14 +00:00
|
|
|
|
2015-04-13 14:17:14 +00:00
|
|
|
// make a copy to play with
|
|
|
|
hostConfig := *container.hostConfig
|
2014-12-23 22:03:20 +00:00
|
|
|
|
2014-12-16 23:06:35 +00:00
|
|
|
if children, err := daemon.Children(container.Name); err == nil {
|
|
|
|
for linkAlias, child := range children {
|
2015-04-13 14:17:14 +00:00
|
|
|
hostConfig.Links = append(hostConfig.Links, fmt.Sprintf("%s:%s", child.Name, linkAlias))
|
2014-06-25 22:24:14 +00:00
|
|
|
}
|
2014-12-16 23:06:35 +00:00
|
|
|
}
|
2015-02-04 19:04:58 +00:00
|
|
|
// we need this trick to preserve empty log driver, so
|
|
|
|
// container will use daemon defaults even if daemon change them
|
2015-04-13 14:17:14 +00:00
|
|
|
if hostConfig.LogConfig.Type == "" {
|
|
|
|
hostConfig.LogConfig = daemon.defaultLogConfig
|
2015-02-04 19:04:58 +00:00
|
|
|
}
|
2014-06-25 22:24:14 +00:00
|
|
|
|
2015-04-13 14:17:14 +00: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 22:24:14 +00:00
|
|
|
|
2015-04-13 14:17:14 +00:00
|
|
|
contJSON := &types.ContainerJSON{
|
|
|
|
Id: container.ID,
|
|
|
|
Created: container.Created,
|
|
|
|
Path: container.Path,
|
|
|
|
Args: container.Args,
|
|
|
|
Config: container.Config,
|
|
|
|
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,
|
|
|
|
Volumes: container.Volumes,
|
|
|
|
VolumesRW: container.VolumesRW,
|
|
|
|
AppArmorProfile: container.AppArmorProfile,
|
|
|
|
ExecIDs: container.GetExecIDs(),
|
|
|
|
HostConfig: &hostConfig,
|
2014-05-20 19:36:15 +00:00
|
|
|
}
|
2015-04-13 14:17:14 +00:00
|
|
|
|
|
|
|
return contJSON, nil
|
2014-05-20 19:36:15 +00:00
|
|
|
}
|
2014-11-17 23:50:09 +00:00
|
|
|
|
2015-04-11 22:15:34 +00:00
|
|
|
func (daemon *Daemon) ContainerExecInspect(id string) (*execConfig, error) {
|
2014-11-17 23:50:09 +00:00
|
|
|
eConfig, err := daemon.getExecConfig(id)
|
|
|
|
if err != nil {
|
2015-04-11 22:15:34 +00:00
|
|
|
return nil, err
|
2014-11-17 23:50:09 +00:00
|
|
|
}
|
|
|
|
|
2015-04-11 22:15:34 +00:00
|
|
|
return eConfig, nil
|
2014-11-17 23:50:09 +00:00
|
|
|
}
|