2014-05-20 15:36:15 -04:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
2014-06-25 18:24:14 -04:00
|
|
|
"fmt"
|
2015-07-26 09:00:53 -04:00
|
|
|
"time"
|
2014-05-20 15:36:15 -04:00
|
|
|
|
2016-09-06 14:18:12 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
2016-02-10 15:16:59 -05:00
|
|
|
"github.com/docker/docker/api/types/backend"
|
2016-09-06 14:18:12 -04:00
|
|
|
networktypes "github.com/docker/docker/api/types/network"
|
|
|
|
"github.com/docker/docker/api/types/versions"
|
|
|
|
"github.com/docker/docker/api/types/versions/v1p20"
|
2015-11-12 14:55:17 -05:00
|
|
|
"github.com/docker/docker/container"
|
2015-10-26 22:35:49 -04:00
|
|
|
"github.com/docker/docker/daemon/network"
|
2014-05-20 15:36:15 -04:00
|
|
|
)
|
|
|
|
|
2015-07-30 17:01:53 -04: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.
|
2016-04-19 10:56:54 -04:00
|
|
|
func (daemon *Daemon) ContainerInspect(name string, size bool, version string) (interface{}, error) {
|
2015-11-24 12:55:45 -05:00
|
|
|
switch {
|
2016-04-19 10:56:54 -04:00
|
|
|
case versions.LessThan(version, "1.20"):
|
2015-11-24 12:55:45 -05:00
|
|
|
return daemon.containerInspectPre120(name)
|
2016-04-19 10:56:54 -04:00
|
|
|
case versions.Equal(version, "1.20"):
|
2015-11-24 12:55:45 -05:00
|
|
|
return daemon.containerInspect120(name)
|
|
|
|
}
|
2016-06-13 22:52:49 -04:00
|
|
|
return daemon.ContainerInspectCurrent(name, size)
|
2015-11-24 12:55:45 -05:00
|
|
|
}
|
|
|
|
|
2016-06-13 22:52:49 -04:00
|
|
|
// ContainerInspectCurrent returns low-level information about a
|
|
|
|
// container in a most recent api version.
|
|
|
|
func (daemon *Daemon) ContainerInspectCurrent(name string, size bool) (*types.ContainerJSON, error) {
|
2015-12-11 12:39:28 -05:00
|
|
|
container, err := daemon.GetContainer(name)
|
2015-04-13 10:17:14 -04:00
|
|
|
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-09-25 08:49:02 -04:00
|
|
|
base, err := daemon.getInspectData(container, size)
|
2015-06-02 17:37:59 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2016-08-23 19:50:15 -04:00
|
|
|
apiNetworks := make(map[string]*networktypes.EndpointSettings)
|
|
|
|
for name, epConf := range container.NetworkSettings.Networks {
|
|
|
|
if epConf.EndpointSettings != nil {
|
|
|
|
apiNetworks[name] = epConf.EndpointSettings
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-16 17:14:58 -04:00
|
|
|
mountPoints := addMountPoints(container)
|
2015-10-26 22:35:49 -04:00
|
|
|
networkSettings := &types.NetworkSettings{
|
2015-10-30 14:57:15 -04:00
|
|
|
NetworkSettingsBase: types.NetworkSettingsBase{
|
2015-10-26 22:35:49 -04: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 14:57:15 -04:00
|
|
|
DefaultNetworkSettings: daemon.getDefaultNetworkSettings(container.NetworkSettings.Networks),
|
2016-08-23 19:50:15 -04:00
|
|
|
Networks: apiNetworks,
|
2015-10-26 22:35:49 -04:00
|
|
|
}
|
2015-06-03 15:21:38 -04:00
|
|
|
|
2015-11-02 11:28:34 -05:00
|
|
|
return &types.ContainerJSON{
|
|
|
|
ContainerJSONBase: base,
|
|
|
|
Mounts: mountPoints,
|
|
|
|
Config: container.Config,
|
|
|
|
NetworkSettings: networkSettings,
|
|
|
|
}, nil
|
2015-06-02 17:37:59 -04:00
|
|
|
}
|
|
|
|
|
2015-11-24 12:55:45 -05:00
|
|
|
// containerInspect120 serializes the master version of a container into a json type.
|
|
|
|
func (daemon *Daemon) containerInspect120(name string) (*v1p20.ContainerJSON, error) {
|
2015-12-11 12:39:28 -05:00
|
|
|
container, err := daemon.GetContainer(name)
|
2015-08-24 13:57:39 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
container.Lock()
|
|
|
|
defer container.Unlock()
|
|
|
|
|
2015-09-25 08:49:02 -04:00
|
|
|
base, err := daemon.getInspectData(container, false)
|
2015-08-24 13:57:39 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
mountPoints := addMountPoints(container)
|
2015-09-24 16:56:57 -04:00
|
|
|
config := &v1p20.ContainerConfig{
|
2015-11-02 11:28:34 -05:00
|
|
|
Config: container.Config,
|
|
|
|
MacAddress: container.Config.MacAddress,
|
|
|
|
NetworkDisabled: container.Config.NetworkDisabled,
|
|
|
|
ExposedPorts: container.Config.ExposedPorts,
|
2015-11-12 14:55:17 -05:00
|
|
|
VolumeDriver: container.HostConfig.VolumeDriver,
|
2015-08-24 13:57:39 -04:00
|
|
|
}
|
2015-10-30 14:57:15 -04:00
|
|
|
networkSettings := daemon.getBackwardsCompatibleNetworkSettings(container.NetworkSettings)
|
2015-08-24 13:57:39 -04:00
|
|
|
|
2015-11-02 11:28:34 -05:00
|
|
|
return &v1p20.ContainerJSON{
|
|
|
|
ContainerJSONBase: base,
|
|
|
|
Mounts: mountPoints,
|
|
|
|
Config: config,
|
|
|
|
NetworkSettings: networkSettings,
|
|
|
|
}, nil
|
2015-08-24 13:57:39 -04:00
|
|
|
}
|
|
|
|
|
2015-11-12 14:55:17 -05:00
|
|
|
func (daemon *Daemon) getInspectData(container *container.Container, size bool) (*types.ContainerJSONBase, error) {
|
2015-04-13 10:17:14 -04:00
|
|
|
// make a copy to play with
|
2015-11-12 14:55:17 -05:00
|
|
|
hostConfig := *container.HostConfig
|
2014-12-23 17:03:20 -05:00
|
|
|
|
2015-09-03 20:51:04 -04:00
|
|
|
children := daemon.children(container)
|
|
|
|
hostConfig.Links = nil // do not expose the internal structure
|
|
|
|
for linkAlias, child := range children {
|
|
|
|
hostConfig.Links = append(hostConfig.Links, fmt.Sprintf("%s:%s", child.Name, linkAlias))
|
2014-12-16 18:06:35 -05:00
|
|
|
}
|
2015-09-03 20:51:04 -04:00
|
|
|
|
2016-09-08 00:23:56 -04:00
|
|
|
// We merge the Ulimits from hostConfig with daemon default
|
|
|
|
daemon.mergeUlimits(&hostConfig)
|
|
|
|
|
2016-04-18 05:48:13 -04:00
|
|
|
var containerHealth *types.Health
|
|
|
|
if container.State.Health != nil {
|
|
|
|
containerHealth = &types.Health{
|
|
|
|
Status: container.State.Health.Status,
|
|
|
|
FailingStreak: container.State.Health.FailingStreak,
|
|
|
|
Log: append([]*types.HealthcheckResult{}, container.State.Health.Log...),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-13 10:17:14 -04:00
|
|
|
containerState := &types.ContainerState{
|
2015-07-27 20:48:27 -04:00
|
|
|
Status: container.State.StateString(),
|
2015-04-13 10:17:14 -04: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,
|
2016-06-14 14:11:43 -04:00
|
|
|
ExitCode: container.State.ExitCode(),
|
|
|
|
Error: container.State.Error(),
|
2015-07-26 09:00:53 -04:00
|
|
|
StartedAt: container.State.StartedAt.Format(time.RFC3339Nano),
|
|
|
|
FinishedAt: container.State.FinishedAt.Format(time.RFC3339Nano),
|
2016-04-18 05:48:13 -04:00
|
|
|
Health: containerHealth,
|
2015-04-13 10:17:14 -04:00
|
|
|
}
|
2014-06-25 18:24:14 -04:00
|
|
|
|
2015-06-02 17:37:59 -04:00
|
|
|
contJSONBase := &types.ContainerJSONBase{
|
2015-10-26 22:35:49 -04:00
|
|
|
ID: container.ID,
|
|
|
|
Created: container.Created.Format(time.RFC3339Nano),
|
|
|
|
Path: container.Path,
|
|
|
|
Args: container.Args,
|
|
|
|
State: containerState,
|
2015-11-18 17:20:54 -05:00
|
|
|
Image: container.ImageID.String(),
|
2015-10-26 22:35:49 -04:00
|
|
|
LogPath: container.LogPath,
|
|
|
|
Name: container.Name,
|
|
|
|
RestartCount: container.RestartCount,
|
|
|
|
Driver: container.Driver,
|
|
|
|
MountLabel: container.MountLabel,
|
|
|
|
ProcessLabel: container.ProcessLabel,
|
2015-11-12 14:55:17 -05:00
|
|
|
ExecIDs: container.GetExecIDs(),
|
2015-10-26 22:35:49 -04:00
|
|
|
HostConfig: &hostConfig,
|
2014-05-20 15:36:15 -04:00
|
|
|
}
|
2015-04-13 10:17:14 -04:00
|
|
|
|
2015-09-25 08:49:02 -04:00
|
|
|
var (
|
|
|
|
sizeRw int64
|
|
|
|
sizeRootFs int64
|
|
|
|
)
|
|
|
|
if size {
|
2015-11-02 20:06:09 -05:00
|
|
|
sizeRw, sizeRootFs = daemon.getSize(container)
|
2015-09-25 08:49:02 -04:00
|
|
|
contJSONBase.SizeRw = &sizeRw
|
|
|
|
contJSONBase.SizeRootFs = &sizeRootFs
|
|
|
|
}
|
|
|
|
|
2015-07-16 17:14:58 -04:00
|
|
|
// Now set any platform-specific fields
|
|
|
|
contJSONBase = setPlatformSpecificContainerFields(container, contJSONBase)
|
|
|
|
|
2015-06-15 14:05:10 -04:00
|
|
|
contJSONBase.GraphDriver.Name = container.Driver
|
2015-11-18 17:20:54 -05:00
|
|
|
|
2015-12-16 17:13:50 -05:00
|
|
|
graphDriverData, err := container.RWLayer.Metadata()
|
2016-08-22 22:09:25 -04:00
|
|
|
// If container is marked as Dead, the container's graphdriver metadata
|
|
|
|
// could have been removed, it will cause error if we try to get the metadata,
|
|
|
|
// we can ignore the error if the container is dead.
|
|
|
|
if err != nil && !container.Dead {
|
2015-06-15 14:05:10 -04:00
|
|
|
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-07-30 17:01:53 -04:00
|
|
|
// ContainerExecInspect returns low-level information about the exec
|
|
|
|
// command. An error is returned if the exec cannot be found.
|
2016-02-10 15:16:59 -05:00
|
|
|
func (daemon *Daemon) ContainerExecInspect(id string) (*backend.ExecInspect, error) {
|
|
|
|
e, err := daemon.getExecConfig(id)
|
2014-11-17 18:50:09 -05:00
|
|
|
if err != nil {
|
2015-04-11 18:15:34 -04:00
|
|
|
return nil, err
|
2014-11-17 18:50:09 -05:00
|
|
|
}
|
2016-02-10 15:16:59 -05:00
|
|
|
|
|
|
|
pc := inspectExecProcessConfig(e)
|
|
|
|
|
|
|
|
return &backend.ExecInspect{
|
|
|
|
ID: e.ID,
|
|
|
|
Running: e.Running,
|
|
|
|
ExitCode: e.ExitCode,
|
|
|
|
ProcessConfig: pc,
|
|
|
|
OpenStdin: e.OpenStdin,
|
|
|
|
OpenStdout: e.OpenStdout,
|
|
|
|
OpenStderr: e.OpenStderr,
|
|
|
|
CanRemove: e.CanRemove,
|
|
|
|
ContainerID: e.ContainerID,
|
|
|
|
DetachKeys: e.DetachKeys,
|
|
|
|
}, nil
|
2014-11-17 18:50:09 -05:00
|
|
|
}
|
2015-06-12 09:25:32 -04:00
|
|
|
|
2015-07-30 17:01:53 -04:00
|
|
|
// VolumeInspect looks up a volume by name. An error is returned if
|
|
|
|
// the volume cannot be found.
|
2015-09-29 13:51:40 -04:00
|
|
|
func (daemon *Daemon) VolumeInspect(name string) (*types.Volume, error) {
|
2015-06-12 09:25:32 -04:00
|
|
|
v, err := daemon.volumes.Get(name)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-04-12 17:09:55 -04:00
|
|
|
apiV := volumeToAPIType(v)
|
|
|
|
apiV.Mountpoint = v.Path()
|
2016-03-07 15:44:43 -05:00
|
|
|
apiV.Status = v.Status()
|
2016-04-12 17:09:55 -04:00
|
|
|
return apiV, nil
|
2015-06-12 09:25:32 -04:00
|
|
|
}
|
2015-10-26 22:35:49 -04:00
|
|
|
|
2015-10-30 14:57:15 -04:00
|
|
|
func (daemon *Daemon) getBackwardsCompatibleNetworkSettings(settings *network.Settings) *v1p20.NetworkSettings {
|
2015-10-26 22:35:49 -04: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 14:57:15 -04:00
|
|
|
DefaultNetworkSettings: daemon.getDefaultNetworkSettings(settings.Networks),
|
2015-10-26 22:35:49 -04:00
|
|
|
}
|
2015-10-30 14:57:15 -04:00
|
|
|
|
2015-10-26 22:35:49 -04:00
|
|
|
return result
|
|
|
|
}
|
2015-10-30 14:57:15 -04:00
|
|
|
|
|
|
|
// getDefaultNetworkSettings creates the deprecated structure that holds the information
|
|
|
|
// about the bridge network for a container.
|
2016-08-23 19:50:15 -04:00
|
|
|
func (daemon *Daemon) getDefaultNetworkSettings(networks map[string]*network.EndpointSettings) types.DefaultNetworkSettings {
|
2015-10-30 14:57:15 -04:00
|
|
|
var settings types.DefaultNetworkSettings
|
|
|
|
|
2016-08-23 19:50:15 -04:00
|
|
|
if defaultNetwork, ok := networks["bridge"]; ok && defaultNetwork.EndpointSettings != nil {
|
2015-10-30 14:57:15 -04:00
|
|
|
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
|
|
|
|
}
|