// containerInspect120 serializes the master version of a container into a json type. func (daemon *Daemon) containerInspect120(name string) (*v1p20.ContainerJSON, error) { container, err := daemon.GetContainer(name) if err != nil { return nil, err } container.Lock() defer container.Unlock() base, err := daemon.getInspectData(container, false) if err != nil { return nil, err } mountPoints := addMountPoints(container) config := &v1p20.ContainerConfig{ Config: container.Config, MacAddress: container.Config.MacAddress, NetworkDisabled: container.Config.NetworkDisabled, ExposedPorts: container.Config.ExposedPorts, VolumeDriver: container.HostConfig.VolumeDriver, } networkSettings := daemon.getBackwardsCompatibleNetworkSettings(container.NetworkSettings) return &v1p20.ContainerJSON{ ContainerJSONBase: base, Mounts: mountPoints, Config: config, NetworkSettings: networkSettings, }, nil }
// ContainerStart starts a container. func (daemon *Daemon) ContainerStart(name string, hostConfig *runconfig.HostConfig) error { container, err := daemon.Get(name) if err != nil { return err } if container.IsPaused() { return derr.ErrorCodeStartPaused } if container.IsRunning() { return derr.ErrorCodeAlreadyStarted } // Windows does not have the backwards compatibility issue here. if runtime.GOOS != "windows" { // This is kept for backward compatibility - hostconfig should be passed when // creating a container, not during start. if hostConfig != nil { logrus.Warn("DEPRECATED: Setting host configuration options when the container starts is deprecated and will be removed in Docker 1.12") container.Lock() if err := parseSecurityOpt(container, hostConfig); err != nil { container.Unlock() return err } container.Unlock() if err := daemon.adaptContainerSettings(hostConfig, false); err != nil { return err } if err := daemon.setHostConfig(container, hostConfig); err != nil { return err } container.InitDNSHostConfig() } } else { if hostConfig != nil { return derr.ErrorCodeHostConfigStart } } // check if hostConfig is in line with the current system settings. // It may happen cgroups are umounted or the like. if _, err = daemon.verifyContainerSettings(container.HostConfig, nil); err != nil { return err } if err := daemon.containerStart(container); err != nil { return err } return nil }
// 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) { container, err := daemon.GetContainer(name) if err != nil { return nil, err } container.Lock() defer container.Unlock() base, err := daemon.getInspectData(container, size) if err != nil { return nil, err } apiNetworks := make(map[string]*networktypes.EndpointSettings) for name, epConf := range container.NetworkSettings.Networks { if epConf.EndpointSettings != nil { apiNetworks[name] = epConf.EndpointSettings } } mountPoints := addMountPoints(container) networkSettings := &types.NetworkSettings{ NetworkSettingsBase: types.NetworkSettingsBase{ 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, }, DefaultNetworkSettings: daemon.getDefaultNetworkSettings(container.NetworkSettings.Networks), Networks: apiNetworks, } return &types.ContainerJSON{ ContainerJSONBase: base, Mounts: mountPoints, Config: container.Config, NetworkSettings: networkSettings, }, nil }
// containerInspectPre120 gets containers for pre 1.20 APIs. func (daemon *Daemon) containerInspectPre120(name string) (*v1p19.ContainerJSON, error) { container, err := daemon.GetContainer(name) if err != nil { return nil, err } container.Lock() defer container.Unlock() base, err := daemon.getInspectData(container, false) if err != nil { return nil, err } 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 } config := &v1p19.ContainerConfig{ Config: container.Config, MacAddress: container.Config.MacAddress, NetworkDisabled: container.Config.NetworkDisabled, ExposedPorts: container.Config.ExposedPorts, VolumeDriver: container.HostConfig.VolumeDriver, Memory: container.HostConfig.Memory, MemorySwap: container.HostConfig.MemorySwap, CPUShares: container.HostConfig.CPUShares, CPUSet: container.HostConfig.CpusetCpus, } networkSettings := daemon.getBackwardsCompatibleNetworkSettings(container.NetworkSettings) return &v1p19.ContainerJSON{ ContainerJSONBase: base, Volumes: volumes, VolumesRW: volumesRW, Config: config, NetworkSettings: networkSettings, }, nil }