2015-05-15 23:34:26 +00:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
2015-11-18 22:20:54 +00:00
|
|
|
"encoding/json"
|
|
|
|
"errors"
|
2015-05-15 23:34:26 +00:00
|
|
|
"fmt"
|
2016-01-08 03:43:11 +00:00
|
|
|
"os"
|
2015-11-18 22:20:54 +00:00
|
|
|
"path/filepath"
|
|
|
|
"runtime"
|
|
|
|
"strings"
|
2015-05-15 23:34:26 +00:00
|
|
|
|
2016-03-10 04:33:21 +00:00
|
|
|
"github.com/Microsoft/hcsshim"
|
2015-09-22 23:05:00 +00:00
|
|
|
"github.com/Sirupsen/logrus"
|
2015-11-12 19:55:17 +00:00
|
|
|
"github.com/docker/docker/container"
|
2015-05-15 23:34:26 +00:00
|
|
|
"github.com/docker/docker/daemon/graphdriver"
|
2016-02-25 01:51:46 +00:00
|
|
|
"github.com/docker/docker/daemon/graphdriver/windows" // register the windows graph driver
|
2015-11-18 22:20:54 +00:00
|
|
|
"github.com/docker/docker/dockerversion"
|
|
|
|
"github.com/docker/docker/image"
|
|
|
|
"github.com/docker/docker/layer"
|
2016-01-08 03:43:11 +00:00
|
|
|
"github.com/docker/docker/pkg/idtools"
|
2016-03-18 18:53:27 +00:00
|
|
|
"github.com/docker/docker/pkg/parsers"
|
2016-02-25 01:51:46 +00:00
|
|
|
"github.com/docker/docker/pkg/sysinfo"
|
2015-10-15 18:40:14 +00:00
|
|
|
"github.com/docker/docker/pkg/system"
|
2016-02-25 01:51:46 +00:00
|
|
|
"github.com/docker/docker/reference"
|
|
|
|
"github.com/docker/docker/runconfig"
|
2016-03-18 18:53:27 +00:00
|
|
|
"github.com/docker/engine-api/types"
|
2016-02-25 01:51:46 +00:00
|
|
|
pblkiodev "github.com/docker/engine-api/types/blkiodev"
|
2016-03-18 18:53:27 +00:00
|
|
|
containertypes "github.com/docker/engine-api/types/container"
|
2015-05-15 23:34:26 +00:00
|
|
|
"github.com/docker/libnetwork"
|
2016-02-18 01:08:11 +00:00
|
|
|
nwconfig "github.com/docker/libnetwork/config"
|
2016-03-10 04:33:21 +00:00
|
|
|
winlibnetwork "github.com/docker/libnetwork/drivers/windows"
|
|
|
|
"github.com/docker/libnetwork/netlabel"
|
|
|
|
"github.com/docker/libnetwork/options"
|
2015-06-12 00:34:20 +00:00
|
|
|
blkiodev "github.com/opencontainers/runc/libcontainer/configs"
|
2015-05-15 23:34:26 +00:00
|
|
|
)
|
|
|
|
|
2015-08-07 16:33:29 +00:00
|
|
|
const (
|
2016-04-05 22:32:40 +00:00
|
|
|
defaultNetworkSpace = "172.16.0.0/12"
|
|
|
|
platformSupported = true
|
|
|
|
windowsMinCPUShares = 1
|
|
|
|
windowsMaxCPUShares = 10000
|
2015-08-07 16:33:29 +00:00
|
|
|
)
|
2015-07-13 19:34:58 +00:00
|
|
|
|
2016-03-18 18:53:27 +00:00
|
|
|
func getBlkioWeightDevices(config *containertypes.HostConfig) ([]blkiodev.WeightDevice, error) {
|
2015-06-12 00:34:20 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2015-12-18 18:36:17 +00:00
|
|
|
func parseSecurityOpt(container *container.Container, config *containertypes.HostConfig) error {
|
2015-05-15 23:34:26 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-03-18 18:53:27 +00:00
|
|
|
func getBlkioReadIOpsDevices(config *containertypes.HostConfig) ([]blkiodev.ThrottleDevice, error) {
|
2015-07-08 11:06:48 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2016-03-18 18:53:27 +00:00
|
|
|
func getBlkioWriteIOpsDevices(config *containertypes.HostConfig) ([]blkiodev.ThrottleDevice, error) {
|
2015-07-08 11:06:48 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2016-03-18 18:53:27 +00:00
|
|
|
func getBlkioReadBpsDevices(config *containertypes.HostConfig) ([]blkiodev.ThrottleDevice, error) {
|
2015-07-08 11:06:48 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2016-03-18 18:53:27 +00:00
|
|
|
func getBlkioWriteBpsDevices(config *containertypes.HostConfig) ([]blkiodev.ThrottleDevice, error) {
|
2015-07-08 11:06:48 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2015-10-08 15:51:41 +00:00
|
|
|
func setupInitLayer(initLayer string, rootUID, rootGID int) error {
|
2015-05-15 23:34:26 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func checkKernel() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-02-18 10:10:31 +00:00
|
|
|
func (daemon *Daemon) getCgroupDriver() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2015-07-30 22:28:11 +00:00
|
|
|
// adaptContainerSettings is called during container creation to modify any
|
|
|
|
// settings necessary in the HostConfig structure.
|
2015-12-18 18:36:17 +00:00
|
|
|
func (daemon *Daemon) adaptContainerSettings(hostConfig *containertypes.HostConfig, adjustCPUShares bool) error {
|
2015-09-24 19:10:41 +00:00
|
|
|
if hostConfig == nil {
|
2015-12-02 02:53:52 +00:00
|
|
|
return nil
|
2015-09-24 19:10:41 +00:00
|
|
|
}
|
|
|
|
|
2015-09-22 23:05:00 +00:00
|
|
|
if hostConfig.CPUShares < 0 {
|
|
|
|
logrus.Warnf("Changing requested CPUShares of %d to minimum allowed of %d", hostConfig.CPUShares, windowsMinCPUShares)
|
|
|
|
hostConfig.CPUShares = windowsMinCPUShares
|
|
|
|
} else if hostConfig.CPUShares > windowsMaxCPUShares {
|
|
|
|
logrus.Warnf("Changing requested CPUShares of %d to maximum allowed of %d", hostConfig.CPUShares, windowsMaxCPUShares)
|
|
|
|
hostConfig.CPUShares = windowsMaxCPUShares
|
|
|
|
}
|
2015-12-02 02:53:52 +00:00
|
|
|
|
|
|
|
return nil
|
2015-07-13 07:17:43 +00:00
|
|
|
}
|
|
|
|
|
2016-03-05 01:24:09 +00:00
|
|
|
func verifyContainerResources(resources *containertypes.Resources, sysInfo *sysinfo.SysInfo) ([]string, error) {
|
|
|
|
warnings := []string{}
|
|
|
|
|
|
|
|
// cpu subsystem checks and adjustments
|
|
|
|
if resources.CPUPercent < 0 || resources.CPUPercent > 100 {
|
|
|
|
return warnings, fmt.Errorf("Range of CPU percent is from 1 to 100")
|
|
|
|
}
|
|
|
|
|
|
|
|
if resources.CPUPercent > 0 && resources.CPUShares > 0 {
|
|
|
|
return warnings, fmt.Errorf("Conflicting options: CPU Shares and CPU Percent cannot both be set")
|
|
|
|
}
|
|
|
|
|
2016-02-25 01:51:46 +00:00
|
|
|
// TODO Windows: Add more validation of resource settings not supported on Windows
|
|
|
|
|
|
|
|
if resources.BlkioWeight > 0 {
|
|
|
|
warnings = append(warnings, "Windows does not support Block I/O weight. Weight discarded.")
|
2016-06-11 17:42:38 +00:00
|
|
|
logrus.Warn("Windows does not support Block I/O weight. --blkio-weight discarded.")
|
2016-02-25 01:51:46 +00:00
|
|
|
resources.BlkioWeight = 0
|
|
|
|
}
|
|
|
|
if len(resources.BlkioWeightDevice) > 0 {
|
|
|
|
warnings = append(warnings, "Windows does not support Block I/O weight_device.")
|
2016-06-11 17:42:38 +00:00
|
|
|
logrus.Warn("Windows does not support Block I/O weight_device. --blkio-weight-device discarded.")
|
2016-02-25 01:51:46 +00:00
|
|
|
resources.BlkioWeightDevice = []*pblkiodev.WeightDevice{}
|
|
|
|
}
|
|
|
|
if len(resources.BlkioDeviceReadBps) > 0 {
|
|
|
|
warnings = append(warnings, "Windows does not support Block read limit in bytes per second.")
|
2016-06-11 17:42:38 +00:00
|
|
|
logrus.Warn("Windows does not support Block I/O read limit in bytes per second. --device-read-bps discarded.")
|
2016-02-25 01:51:46 +00:00
|
|
|
resources.BlkioDeviceReadBps = []*pblkiodev.ThrottleDevice{}
|
|
|
|
}
|
|
|
|
if len(resources.BlkioDeviceWriteBps) > 0 {
|
|
|
|
warnings = append(warnings, "Windows does not support Block write limit in bytes per second.")
|
2016-06-11 17:42:38 +00:00
|
|
|
logrus.Warn("Windows does not support Block I/O write limit in bytes per second. --device-write-bps discarded.")
|
2016-02-25 01:51:46 +00:00
|
|
|
resources.BlkioDeviceWriteBps = []*pblkiodev.ThrottleDevice{}
|
|
|
|
}
|
|
|
|
if len(resources.BlkioDeviceReadIOps) > 0 {
|
|
|
|
warnings = append(warnings, "Windows does not support Block read limit in IO per second.")
|
2016-06-11 17:42:38 +00:00
|
|
|
logrus.Warn("Windows does not support Block I/O read limit in IO per second. -device-read-iops discarded.")
|
2016-02-25 01:51:46 +00:00
|
|
|
resources.BlkioDeviceReadIOps = []*pblkiodev.ThrottleDevice{}
|
|
|
|
}
|
|
|
|
if len(resources.BlkioDeviceWriteIOps) > 0 {
|
|
|
|
warnings = append(warnings, "Windows does not support Block write limit in IO per second.")
|
2016-06-11 17:42:38 +00:00
|
|
|
logrus.Warn("Windows does not support Block I/O write limit in IO per second. --device-write-iops discarded.")
|
2016-02-25 01:51:46 +00:00
|
|
|
resources.BlkioDeviceWriteIOps = []*pblkiodev.ThrottleDevice{}
|
|
|
|
}
|
2016-03-05 01:24:09 +00:00
|
|
|
return warnings, nil
|
|
|
|
}
|
|
|
|
|
2015-07-30 22:28:11 +00:00
|
|
|
// verifyPlatformContainerSettings performs platform-specific validation of the
|
|
|
|
// hostconfig and config structures.
|
2016-02-24 05:36:47 +00:00
|
|
|
func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *containertypes.HostConfig, config *containertypes.Config, update bool) ([]string, error) {
|
2016-03-05 01:24:09 +00:00
|
|
|
warnings := []string{}
|
|
|
|
|
|
|
|
w, err := verifyContainerResources(&hostConfig.Resources, nil)
|
|
|
|
warnings = append(warnings, w...)
|
|
|
|
if err != nil {
|
|
|
|
return warnings, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return warnings, nil
|
2015-05-15 23:34:26 +00:00
|
|
|
}
|
|
|
|
|
2016-01-23 02:15:09 +00:00
|
|
|
// verifyDaemonSettings performs validation of daemon config struct
|
|
|
|
func verifyDaemonSettings(config *Config) error {
|
2015-05-15 23:34:26 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-07-11 19:32:08 +00:00
|
|
|
// checkSystem validates platform-specific requirements
|
2015-05-15 23:34:26 +00:00
|
|
|
func checkSystem() error {
|
|
|
|
// Validate the OS version. Note that docker.exe must be manifested for this
|
|
|
|
// call to return the correct version.
|
2016-03-17 01:45:40 +00:00
|
|
|
osv := system.GetOSVersion()
|
2015-10-15 18:40:14 +00:00
|
|
|
if osv.MajorVersion < 10 {
|
2015-05-15 23:34:26 +00:00
|
|
|
return fmt.Errorf("This version of Windows does not support the docker daemon")
|
|
|
|
}
|
2016-04-05 22:32:40 +00:00
|
|
|
if osv.Build < 14300 {
|
|
|
|
return fmt.Errorf("The Windows daemon requires Windows Server 2016 Technical Preview 5 build 14300 or later")
|
2015-11-11 22:47:02 +00:00
|
|
|
}
|
2015-05-15 23:34:26 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// configureKernelSecuritySupport configures and validate security support for the kernel
|
|
|
|
func configureKernelSecuritySupport(config *Config, driverName string) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-12-02 10:26:30 +00:00
|
|
|
// configureMaxThreads sets the Go runtime max threads threshold
|
|
|
|
func configureMaxThreads(config *Config) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-03-10 04:33:21 +00:00
|
|
|
func (daemon *Daemon) initNetworkController(config *Config) (libnetwork.NetworkController, error) {
|
|
|
|
netOptions, err := daemon.networkOptions(config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
controller, err := libnetwork.New(netOptions...)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error obtaining controller instance: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
hnsresponse, err := hcsshim.HNSListNetworkRequest("GET", "", "")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove networks not present in HNS
|
|
|
|
for _, v := range controller.Networks() {
|
|
|
|
options := v.Info().DriverOptions()
|
|
|
|
hnsid := options[winlibnetwork.HNSID]
|
|
|
|
found := false
|
|
|
|
|
|
|
|
for _, v := range hnsresponse {
|
|
|
|
if v.Id == hnsid {
|
|
|
|
found = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !found {
|
|
|
|
err = v.Delete()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-08 07:33:16 +00:00
|
|
|
_, err = controller.NewNetwork("null", "none", "", libnetwork.NetworkOptionPersist(false))
|
2016-03-10 04:33:21 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// discover and add HNS networks to windows
|
|
|
|
// network that exist are removed and added again
|
|
|
|
for _, v := range hnsresponse {
|
|
|
|
var n libnetwork.Network
|
|
|
|
s := func(current libnetwork.Network) bool {
|
|
|
|
options := current.Info().DriverOptions()
|
|
|
|
if options[winlibnetwork.HNSID] == v.Id {
|
|
|
|
n = current
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
controller.WalkNetworks(s)
|
|
|
|
if n != nil {
|
|
|
|
v.Name = n.Name()
|
|
|
|
n.Delete()
|
|
|
|
}
|
|
|
|
|
|
|
|
netOption := map[string]string{
|
|
|
|
winlibnetwork.NetworkName: v.Name,
|
|
|
|
winlibnetwork.HNSID: v.Id,
|
|
|
|
}
|
|
|
|
|
|
|
|
v4Conf := []*libnetwork.IpamConf{}
|
|
|
|
for _, subnet := range v.Subnets {
|
|
|
|
ipamV4Conf := libnetwork.IpamConf{}
|
|
|
|
ipamV4Conf.PreferredPool = subnet.AddressPrefix
|
|
|
|
ipamV4Conf.Gateway = subnet.GatewayAddress
|
|
|
|
v4Conf = append(v4Conf, &ipamV4Conf)
|
|
|
|
}
|
|
|
|
|
|
|
|
name := v.Name
|
|
|
|
// There is only one nat network supported in windows.
|
|
|
|
// If it exists with a different name add it as the default name
|
|
|
|
if runconfig.DefaultDaemonNetworkMode() == containertypes.NetworkMode(strings.ToLower(v.Type)) {
|
|
|
|
name = runconfig.DefaultDaemonNetworkMode().NetworkName()
|
|
|
|
}
|
|
|
|
|
|
|
|
v6Conf := []*libnetwork.IpamConf{}
|
2016-05-08 07:33:16 +00:00
|
|
|
_, err := controller.NewNetwork(strings.ToLower(v.Type), name, "",
|
2016-03-10 04:33:21 +00:00
|
|
|
libnetwork.NetworkOptionGeneric(options.Generic{
|
|
|
|
netlabel.GenericData: netOption,
|
|
|
|
}),
|
|
|
|
libnetwork.NetworkOptionIpam("default", "", v4Conf, v6Conf, nil),
|
|
|
|
)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
logrus.Errorf("Error occurred when creating network %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !config.DisableBridge {
|
|
|
|
// Initialize default driver "bridge"
|
|
|
|
if err := initBridgeDriver(controller, config); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return controller, nil
|
2015-05-15 23:34:26 +00:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:33:21 +00:00
|
|
|
func initBridgeDriver(controller libnetwork.NetworkController, config *Config) error {
|
|
|
|
if _, err := controller.NetworkByName(runconfig.DefaultDaemonNetworkMode().NetworkName()); err == nil {
|
|
|
|
return nil
|
2015-07-13 19:34:58 +00:00
|
|
|
}
|
2016-03-10 04:33:21 +00:00
|
|
|
|
|
|
|
netOption := map[string]string{
|
|
|
|
winlibnetwork.NetworkName: runconfig.DefaultDaemonNetworkMode().NetworkName(),
|
|
|
|
}
|
|
|
|
|
|
|
|
ipamV4Conf := libnetwork.IpamConf{}
|
|
|
|
if config.bridgeConfig.FixedCIDR == "" {
|
|
|
|
ipamV4Conf.PreferredPool = defaultNetworkSpace
|
|
|
|
} else {
|
|
|
|
ipamV4Conf.PreferredPool = config.bridgeConfig.FixedCIDR
|
|
|
|
}
|
|
|
|
|
|
|
|
v4Conf := []*libnetwork.IpamConf{&ipamV4Conf}
|
|
|
|
v6Conf := []*libnetwork.IpamConf{}
|
|
|
|
|
2016-05-08 07:33:16 +00:00
|
|
|
_, err := controller.NewNetwork(string(runconfig.DefaultDaemonNetworkMode()), runconfig.DefaultDaemonNetworkMode().NetworkName(), "",
|
2016-03-10 04:33:21 +00:00
|
|
|
libnetwork.NetworkOptionGeneric(options.Generic{
|
|
|
|
netlabel.GenericData: netOption,
|
|
|
|
}),
|
|
|
|
libnetwork.NetworkOptionIpam("default", "", v4Conf, v6Conf, nil),
|
|
|
|
)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error creating default network: %v", err)
|
|
|
|
}
|
|
|
|
return nil
|
2015-05-15 23:34:26 +00:00
|
|
|
}
|
2015-06-23 17:13:42 +00:00
|
|
|
|
2015-07-30 21:01:53 +00:00
|
|
|
// registerLinks sets up links between containers and writes the
|
2015-11-16 05:32:31 +00:00
|
|
|
// configuration out for persistence. As of Windows TP4, links are not supported.
|
2015-12-18 18:36:17 +00:00
|
|
|
func (daemon *Daemon) registerLinks(container *container.Container, hostConfig *containertypes.HostConfig) error {
|
2015-06-23 17:13:42 +00:00
|
|
|
return nil
|
|
|
|
}
|
2015-07-16 21:14:58 +00:00
|
|
|
|
2016-03-18 18:53:27 +00:00
|
|
|
func (daemon *Daemon) cleanupMountsByID(in string) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-08-03 22:05:34 +00:00
|
|
|
func (daemon *Daemon) cleanupMounts() error {
|
|
|
|
return nil
|
|
|
|
}
|
2015-11-03 01:06:09 +00:00
|
|
|
|
2016-01-08 03:43:11 +00:00
|
|
|
func setupRemappedRoot(config *Config) ([]idtools.IDMap, []idtools.IDMap, error) {
|
|
|
|
return nil, nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func setupDaemonRoot(config *Config, rootDir string, rootUID, rootGID int) error {
|
|
|
|
config.Root = rootDir
|
|
|
|
// Create the root directory if it doesn't exists
|
|
|
|
if err := system.MkdirAll(config.Root, 0700); err != nil && !os.IsExist(err) {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-03-19 03:09:54 +00:00
|
|
|
// runasHyperVContainer returns true if we are going to run as a Hyper-V container
|
|
|
|
func (daemon *Daemon) runAsHyperVContainer(container *container.Container) bool {
|
2016-03-18 18:53:27 +00:00
|
|
|
if container.HostConfig.Isolation.IsDefault() {
|
|
|
|
// Container is set to use the default, so take the default from the daemon configuration
|
2016-03-19 03:09:54 +00:00
|
|
|
return daemon.defaultIsolation.IsHyperV()
|
2016-03-18 18:53:27 +00:00
|
|
|
}
|
|
|
|
|
2016-03-19 03:09:54 +00:00
|
|
|
// Container is requesting an isolation mode. Honour it.
|
|
|
|
return container.HostConfig.Isolation.IsHyperV()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// conditionalMountOnStart is a platform specific helper function during the
|
|
|
|
// container start to call mount.
|
|
|
|
func (daemon *Daemon) conditionalMountOnStart(container *container.Container) error {
|
2015-11-03 01:06:09 +00:00
|
|
|
// We do not mount if a Hyper-V container
|
2016-03-19 03:09:54 +00:00
|
|
|
if !daemon.runAsHyperVContainer(container) {
|
|
|
|
return daemon.Mount(container)
|
2015-11-03 01:06:09 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// conditionalUnmountOnCleanup is a platform specific helper function called
|
|
|
|
// during the cleanup of a container to unmount.
|
2016-03-18 18:53:27 +00:00
|
|
|
func (daemon *Daemon) conditionalUnmountOnCleanup(container *container.Container) error {
|
2015-11-03 01:06:09 +00:00
|
|
|
// We do not unmount if a Hyper-V container
|
2016-03-19 03:09:54 +00:00
|
|
|
if !daemon.runAsHyperVContainer(container) {
|
2016-03-18 18:53:27 +00:00
|
|
|
return daemon.Unmount(container)
|
2015-11-18 22:20:54 +00:00
|
|
|
}
|
2016-03-18 18:53:27 +00:00
|
|
|
return nil
|
2015-11-18 22:20:54 +00:00
|
|
|
}
|
|
|
|
|
2015-12-16 20:32:16 +00:00
|
|
|
func restoreCustomImage(is image.Store, ls layer.Store, rs reference.Store) error {
|
|
|
|
type graphDriverStore interface {
|
|
|
|
GraphDriver() graphdriver.Driver
|
|
|
|
}
|
|
|
|
|
|
|
|
gds, ok := ls.(graphDriverStore)
|
|
|
|
if !ok {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
driver := gds.GraphDriver()
|
|
|
|
wd, ok := driver.(*windows.Driver)
|
|
|
|
if !ok {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
imageInfos, err := wd.GetCustomImageInfos()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert imageData to valid image configuration
|
2016-03-17 01:45:40 +00:00
|
|
|
for _, info := range imageInfos {
|
|
|
|
name := strings.ToLower(info.Name)
|
2015-12-16 20:32:16 +00:00
|
|
|
|
|
|
|
type registrar interface {
|
|
|
|
RegisterDiffID(graphID string, size int64) (layer.Layer, error)
|
|
|
|
}
|
|
|
|
r, ok := ls.(registrar)
|
|
|
|
if !ok {
|
|
|
|
return errors.New("Layerstore doesn't support RegisterDiffID")
|
|
|
|
}
|
2016-03-17 01:45:40 +00:00
|
|
|
if _, err := r.RegisterDiffID(info.ID, info.Size); err != nil {
|
2015-12-16 20:32:16 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
// layer is intentionally not released
|
|
|
|
|
2016-03-29 01:14:05 +00:00
|
|
|
rootFS := image.NewRootFSWithBaseLayer(filepath.Base(info.Path))
|
2015-12-16 20:32:16 +00:00
|
|
|
|
|
|
|
// Create history for base layer
|
|
|
|
config, err := json.Marshal(&image.Image{
|
|
|
|
V1Image: image.V1Image{
|
|
|
|
DockerVersion: dockerversion.Version,
|
|
|
|
Architecture: runtime.GOARCH,
|
|
|
|
OS: runtime.GOOS,
|
2016-03-17 01:45:40 +00:00
|
|
|
Created: info.CreatedTime,
|
2015-12-16 20:32:16 +00:00
|
|
|
},
|
2016-03-17 01:45:40 +00:00
|
|
|
RootFS: rootFS,
|
|
|
|
History: []image.History{},
|
|
|
|
OSVersion: info.OSVersion,
|
|
|
|
OSFeatures: info.OSFeatures,
|
2015-12-16 20:32:16 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
named, err := reference.ParseNamed(name)
|
2015-11-18 22:20:54 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2015-11-03 01:06:09 +00:00
|
|
|
}
|
2015-11-18 22:20:54 +00:00
|
|
|
|
2016-03-17 01:45:40 +00:00
|
|
|
ref, err := reference.WithTag(named, info.Version)
|
2015-12-16 20:32:16 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2015-11-18 22:20:54 +00:00
|
|
|
}
|
|
|
|
|
2015-12-16 20:32:16 +00:00
|
|
|
id, err := is.Create(config)
|
|
|
|
if err != nil {
|
2016-04-08 22:04:04 +00:00
|
|
|
logrus.Warnf("Failed to restore custom image %s with error: %s.", name, err)
|
2016-04-07 22:58:57 +00:00
|
|
|
logrus.Warnf("Skipping image %s...", name)
|
|
|
|
continue
|
2015-12-16 20:32:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := rs.AddTag(ref, id, true); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-11-18 22:20:54 +00:00
|
|
|
|
2015-12-16 20:32:16 +00:00
|
|
|
logrus.Debugf("Registered base layer %s as %s", ref, id)
|
|
|
|
}
|
2015-11-18 22:20:54 +00:00
|
|
|
return nil
|
2015-11-03 01:06:09 +00:00
|
|
|
}
|
2016-02-18 01:08:11 +00:00
|
|
|
|
2016-03-10 04:33:21 +00:00
|
|
|
func driverOptions(config *Config) []nwconfig.Option {
|
|
|
|
return []nwconfig.Option{}
|
2016-02-18 01:08:11 +00:00
|
|
|
}
|
2016-03-18 18:53:27 +00:00
|
|
|
|
|
|
|
func (daemon *Daemon) stats(c *container.Container) (*types.StatsJSON, error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// setDefaultIsolation determine the default isolation mode for the
|
|
|
|
// daemon to run in. This is only applicable on Windows
|
|
|
|
func (daemon *Daemon) setDefaultIsolation() error {
|
|
|
|
daemon.defaultIsolation = containertypes.Isolation("process")
|
2016-04-15 00:12:02 +00:00
|
|
|
// On client SKUs, default to Hyper-V
|
|
|
|
if system.IsWindowsClient() {
|
|
|
|
daemon.defaultIsolation = containertypes.Isolation("hyperv")
|
|
|
|
}
|
2016-03-18 18:53:27 +00:00
|
|
|
for _, option := range daemon.configStore.ExecOptions {
|
|
|
|
key, val, err := parsers.ParseKeyValueOpt(option)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
key = strings.ToLower(key)
|
|
|
|
switch key {
|
|
|
|
|
|
|
|
case "isolation":
|
|
|
|
if !containertypes.Isolation(val).IsValid() {
|
|
|
|
return fmt.Errorf("Invalid exec-opt value for 'isolation':'%s'", val)
|
|
|
|
}
|
|
|
|
if containertypes.Isolation(val).IsHyperV() {
|
|
|
|
daemon.defaultIsolation = containertypes.Isolation("hyperv")
|
|
|
|
}
|
2016-04-15 00:12:02 +00:00
|
|
|
if containertypes.Isolation(val).IsProcess() {
|
|
|
|
if system.IsWindowsClient() {
|
|
|
|
return fmt.Errorf("Windows client operating systems only support Hyper-V containers")
|
|
|
|
}
|
|
|
|
daemon.defaultIsolation = containertypes.Isolation("process")
|
|
|
|
}
|
2016-03-18 18:53:27 +00:00
|
|
|
default:
|
|
|
|
return fmt.Errorf("Unrecognised exec-opt '%s'\n", key)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
logrus.Infof("Windows default isolation mode: %s", daemon.defaultIsolation)
|
|
|
|
return nil
|
|
|
|
}
|
2016-03-21 16:56:51 +00:00
|
|
|
|
|
|
|
func rootFSToAPIType(rootfs *image.RootFS) types.RootFS {
|
|
|
|
var layers []string
|
|
|
|
for _, l := range rootfs.DiffIDs {
|
|
|
|
layers = append(layers, l.String())
|
|
|
|
}
|
|
|
|
return types.RootFS{
|
|
|
|
Type: rootfs.Type,
|
|
|
|
Layers: layers,
|
|
|
|
BaseLayer: rootfs.BaseLayer,
|
|
|
|
}
|
|
|
|
}
|