2014-05-20 19:36:15 +00:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
2014-06-25 22:24:14 +00:00
|
|
|
"fmt"
|
2015-07-26 13:00:53 +00:00
|
|
|
"time"
|
2014-05-20 19:36:15 +00:00
|
|
|
|
2015-04-13 14:17:14 +00:00
|
|
|
"github.com/docker/docker/api/types"
|
2015-09-24 20:56:57 +00:00
|
|
|
"github.com/docker/docker/api/types/versions/v1p20"
|
2015-11-20 22:35:16 +00:00
|
|
|
"github.com/docker/docker/daemon/exec"
|
2015-10-27 02:35:49 +00:00
|
|
|
"github.com/docker/docker/daemon/network"
|
2014-05-20 19:36:15 +00:00
|
|
|
)
|
|
|
|
|
2015-07-30 21:01:53 +00:00
|
|
|
// ContainerInspect returns low-level information about a
|
|
|
|
// container. Returns an error if the container cannot be found, or if
|
|
|
|
// there is an error getting the data.
|
2015-09-25 12:49:02 +00:00
|
|
|
func (daemon *Daemon) ContainerInspect(name string, size bool) (*types.ContainerJSON, error) {
|
2015-09-29 17:51:40 +00:00
|
|
|
container, err := daemon.Get(name)
|
2015-04-13 14:17:14 +00:00
|
|
|
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-09-25 12:49:02 +00:00
|
|
|
base, err := daemon.getInspectData(container, size)
|
2015-06-02 21:37:59 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2015-07-16 21:14:58 +00:00
|
|
|
mountPoints := addMountPoints(container)
|
2015-10-27 02:35:49 +00:00
|
|
|
networkSettings := &types.NetworkSettings{
|
2015-10-30 18:57:15 +00:00
|
|
|
NetworkSettingsBase: types.NetworkSettingsBase{
|
2015-10-27 02:35:49 +00:00
|
|
|
Bridge: container.NetworkSettings.Bridge,
|
|
|
|
SandboxID: container.NetworkSettings.SandboxID,
|
|
|
|
HairpinMode: container.NetworkSettings.HairpinMode,
|
|
|
|
LinkLocalIPv6Address: container.NetworkSettings.LinkLocalIPv6Address,
|
|
|
|
LinkLocalIPv6PrefixLen: container.NetworkSettings.LinkLocalIPv6PrefixLen,
|
|
|
|
Ports: container.NetworkSettings.Ports,
|
|
|
|
SandboxKey: container.NetworkSettings.SandboxKey,
|
|
|
|
SecondaryIPAddresses: container.NetworkSettings.SecondaryIPAddresses,
|
|
|
|
SecondaryIPv6Addresses: container.NetworkSettings.SecondaryIPv6Addresses,
|
|
|
|
},
|
2015-10-30 18:57:15 +00:00
|
|
|
DefaultNetworkSettings: daemon.getDefaultNetworkSettings(container.NetworkSettings.Networks),
|
|
|
|
Networks: container.NetworkSettings.Networks,
|
2015-10-27 02:35:49 +00:00
|
|
|
}
|
2015-06-03 19:21:38 +00:00
|
|
|
|
2015-11-02 16:28:34 +00:00
|
|
|
return &types.ContainerJSON{
|
|
|
|
ContainerJSONBase: base,
|
|
|
|
Mounts: mountPoints,
|
|
|
|
Config: container.Config,
|
|
|
|
NetworkSettings: networkSettings,
|
|
|
|
}, nil
|
2015-06-02 21:37:59 +00:00
|
|
|
}
|
|
|
|
|
2015-08-24 17:57:39 +00:00
|
|
|
// ContainerInspect120 serializes the master version of a container into a json type.
|
2015-09-24 20:56:57 +00:00
|
|
|
func (daemon *Daemon) ContainerInspect120(name string) (*v1p20.ContainerJSON, error) {
|
2015-09-29 17:51:40 +00:00
|
|
|
container, err := daemon.Get(name)
|
2015-08-24 17:57:39 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
container.Lock()
|
|
|
|
defer container.Unlock()
|
|
|
|
|
2015-09-25 12:49:02 +00:00
|
|
|
base, err := daemon.getInspectData(container, false)
|
2015-08-24 17:57:39 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
mountPoints := addMountPoints(container)
|
2015-09-24 20:56:57 +00:00
|
|
|
config := &v1p20.ContainerConfig{
|
2015-11-02 16:28:34 +00:00
|
|
|
Config: container.Config,
|
|
|
|
MacAddress: container.Config.MacAddress,
|
|
|
|
NetworkDisabled: container.Config.NetworkDisabled,
|
|
|
|
ExposedPorts: container.Config.ExposedPorts,
|
|
|
|
VolumeDriver: container.hostConfig.VolumeDriver,
|
2015-08-24 17:57:39 +00:00
|
|
|
}
|
2015-10-30 18:57:15 +00:00
|
|
|
networkSettings := daemon.getBackwardsCompatibleNetworkSettings(container.NetworkSettings)
|
2015-08-24 17:57:39 +00:00
|
|
|
|
2015-11-02 16:28:34 +00:00
|
|
|
return &v1p20.ContainerJSON{
|
|
|
|
ContainerJSONBase: base,
|
|
|
|
Mounts: mountPoints,
|
|
|
|
Config: config,
|
|
|
|
NetworkSettings: networkSettings,
|
|
|
|
}, nil
|
2015-08-24 17:57:39 +00:00
|
|
|
}
|
|
|
|
|
2015-09-25 12:49:02 +00:00
|
|
|
func (daemon *Daemon) getInspectData(container *Container, size bool) (*types.ContainerJSONBase, error) {
|
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
|
|
|
|
2015-09-29 17:51:40 +00:00
|
|
|
if children, err := daemon.children(container.Name); err == nil {
|
2014-12-16 23:06:35 +00:00
|
|
|
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 == "" {
|
2015-08-17 15:35:34 +00:00
|
|
|
hostConfig.LogConfig.Type = daemon.defaultLogConfig.Type
|
|
|
|
}
|
|
|
|
|
2015-08-17 22:27:44 +00:00
|
|
|
if len(hostConfig.LogConfig.Config) == 0 {
|
2015-08-17 15:35:34 +00:00
|
|
|
hostConfig.LogConfig.Config = daemon.defaultLogConfig.Config
|
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{
|
2015-07-28 00:48:27 +00:00
|
|
|
Status: container.State.StateString(),
|
2015-04-13 14:17:14 +00:00
|
|
|
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,
|
2015-07-26 13:00:53 +00:00
|
|
|
StartedAt: container.State.StartedAt.Format(time.RFC3339Nano),
|
|
|
|
FinishedAt: container.State.FinishedAt.Format(time.RFC3339Nano),
|
2015-04-13 14:17:14 +00:00
|
|
|
}
|
2014-06-25 22:24:14 +00:00
|
|
|
|
2015-06-02 21:37:59 +00:00
|
|
|
contJSONBase := &types.ContainerJSONBase{
|
2015-10-27 02:35:49 +00:00
|
|
|
ID: container.ID,
|
|
|
|
Created: container.Created.Format(time.RFC3339Nano),
|
|
|
|
Path: container.Path,
|
|
|
|
Args: container.Args,
|
|
|
|
State: containerState,
|
|
|
|
Image: container.ImageID,
|
|
|
|
LogPath: container.LogPath,
|
|
|
|
Name: container.Name,
|
|
|
|
RestartCount: container.RestartCount,
|
|
|
|
Driver: container.Driver,
|
|
|
|
MountLabel: container.MountLabel,
|
|
|
|
ProcessLabel: container.ProcessLabel,
|
|
|
|
ExecIDs: container.getExecIDs(),
|
|
|
|
HostConfig: &hostConfig,
|
2014-05-20 19:36:15 +00:00
|
|
|
}
|
2015-04-13 14:17:14 +00:00
|
|
|
|
2015-09-25 12:49:02 +00:00
|
|
|
var (
|
|
|
|
sizeRw int64
|
|
|
|
sizeRootFs int64
|
|
|
|
)
|
|
|
|
if size {
|
2015-11-03 01:06:09 +00:00
|
|
|
sizeRw, sizeRootFs = daemon.getSize(container)
|
2015-09-25 12:49:02 +00:00
|
|
|
contJSONBase.SizeRw = &sizeRw
|
|
|
|
contJSONBase.SizeRootFs = &sizeRootFs
|
|
|
|
}
|
|
|
|
|
2015-07-16 21:14:58 +00:00
|
|
|
// Now set any platform-specific fields
|
|
|
|
contJSONBase = setPlatformSpecificContainerFields(container, contJSONBase)
|
|
|
|
|
2015-06-15 18:05:10 +00: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 21:37:59 +00:00
|
|
|
return contJSONBase, nil
|
2014-05-20 19:36:15 +00:00
|
|
|
}
|
2014-11-17 23:50:09 +00:00
|
|
|
|
2015-07-30 21:01:53 +00:00
|
|
|
// ContainerExecInspect returns low-level information about the exec
|
|
|
|
// command. An error is returned if the exec cannot be found.
|
2015-11-20 22:35:16 +00:00
|
|
|
func (daemon *Daemon) ContainerExecInspect(id string) (*exec.Config, 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
|
|
|
}
|
2015-06-12 13:25:32 +00:00
|
|
|
|
2015-07-30 21:01:53 +00:00
|
|
|
// VolumeInspect looks up a volume by name. An error is returned if
|
|
|
|
// the volume cannot be found.
|
2015-09-29 17:51:40 +00:00
|
|
|
func (daemon *Daemon) VolumeInspect(name string) (*types.Volume, error) {
|
2015-06-12 13:25:32 +00:00
|
|
|
v, err := daemon.volumes.Get(name)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return volumeToAPIType(v), nil
|
|
|
|
}
|
2015-10-27 02:35:49 +00:00
|
|
|
|
2015-10-30 18:57:15 +00:00
|
|
|
func (daemon *Daemon) getBackwardsCompatibleNetworkSettings(settings *network.Settings) *v1p20.NetworkSettings {
|
2015-10-27 02:35:49 +00:00
|
|
|
result := &v1p20.NetworkSettings{
|
|
|
|
NetworkSettingsBase: types.NetworkSettingsBase{
|
|
|
|
Bridge: settings.Bridge,
|
|
|
|
SandboxID: settings.SandboxID,
|
|
|
|
HairpinMode: settings.HairpinMode,
|
|
|
|
LinkLocalIPv6Address: settings.LinkLocalIPv6Address,
|
|
|
|
LinkLocalIPv6PrefixLen: settings.LinkLocalIPv6PrefixLen,
|
|
|
|
Ports: settings.Ports,
|
|
|
|
SandboxKey: settings.SandboxKey,
|
|
|
|
SecondaryIPAddresses: settings.SecondaryIPAddresses,
|
|
|
|
SecondaryIPv6Addresses: settings.SecondaryIPv6Addresses,
|
|
|
|
},
|
2015-10-30 18:57:15 +00:00
|
|
|
DefaultNetworkSettings: daemon.getDefaultNetworkSettings(settings.Networks),
|
2015-10-27 02:35:49 +00:00
|
|
|
}
|
2015-10-30 18:57:15 +00:00
|
|
|
|
2015-10-27 02:35:49 +00:00
|
|
|
return result
|
|
|
|
}
|
2015-10-30 18:57:15 +00:00
|
|
|
|
|
|
|
// getDefaultNetworkSettings creates the deprecated structure that holds the information
|
|
|
|
// about the bridge network for a container.
|
|
|
|
func (daemon *Daemon) getDefaultNetworkSettings(networks map[string]*network.EndpointSettings) types.DefaultNetworkSettings {
|
|
|
|
var settings types.DefaultNetworkSettings
|
|
|
|
|
|
|
|
if defaultNetwork, ok := networks["bridge"]; ok {
|
|
|
|
settings.EndpointID = defaultNetwork.EndpointID
|
|
|
|
settings.Gateway = defaultNetwork.Gateway
|
|
|
|
settings.GlobalIPv6Address = defaultNetwork.GlobalIPv6Address
|
|
|
|
settings.GlobalIPv6PrefixLen = defaultNetwork.GlobalIPv6PrefixLen
|
|
|
|
settings.IPAddress = defaultNetwork.IPAddress
|
|
|
|
settings.IPPrefixLen = defaultNetwork.IPPrefixLen
|
|
|
|
settings.IPv6Gateway = defaultNetwork.IPv6Gateway
|
|
|
|
settings.MacAddress = defaultNetwork.MacAddress
|
|
|
|
}
|
|
|
|
return settings
|
|
|
|
}
|