2015-05-16 02:34:26 +03:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
2015-11-19 01:20:54 +03:00
|
|
|
"encoding/json"
|
|
|
|
"errors"
|
2015-05-16 02:34:26 +03:00
|
|
|
"fmt"
|
2015-11-19 01:20:54 +03:00
|
|
|
"path/filepath"
|
|
|
|
"runtime"
|
|
|
|
"strings"
|
2015-05-16 02:34:26 +03:00
|
|
|
|
2015-09-23 02:05:00 +03:00
|
|
|
"github.com/Sirupsen/logrus"
|
2015-11-19 01:20:54 +03:00
|
|
|
"github.com/docker/distribution/reference"
|
2015-11-12 22:55:17 +03:00
|
|
|
"github.com/docker/docker/container"
|
2015-05-16 02:34:26 +03:00
|
|
|
"github.com/docker/docker/daemon/graphdriver"
|
2015-11-19 01:20:54 +03:00
|
|
|
"github.com/docker/docker/dockerversion"
|
|
|
|
"github.com/docker/docker/image"
|
|
|
|
"github.com/docker/docker/layer"
|
|
|
|
"github.com/docker/docker/tag"
|
2015-07-31 00:01:53 +03:00
|
|
|
// register the windows graph driver
|
2015-11-19 01:20:54 +03:00
|
|
|
"github.com/docker/docker/daemon/graphdriver/windows"
|
2015-10-15 21:40:14 +03:00
|
|
|
"github.com/docker/docker/pkg/system"
|
2015-05-16 02:34:26 +03:00
|
|
|
"github.com/docker/docker/runconfig"
|
|
|
|
"github.com/docker/libnetwork"
|
2015-06-12 03:34:20 +03:00
|
|
|
blkiodev "github.com/opencontainers/runc/libcontainer/configs"
|
2015-05-16 02:34:26 +03:00
|
|
|
)
|
|
|
|
|
2015-08-07 19:33:29 +03:00
|
|
|
const (
|
2015-07-31 00:01:53 +03:00
|
|
|
defaultVirtualSwitch = "Virtual Switch"
|
2015-08-07 19:33:29 +03:00
|
|
|
platformSupported = true
|
2015-09-23 02:05:00 +03:00
|
|
|
windowsMinCPUShares = 1
|
2015-11-12 21:58:20 +03:00
|
|
|
windowsMaxCPUShares = 10000
|
2015-08-07 19:33:29 +03:00
|
|
|
)
|
2015-07-13 22:34:58 +03:00
|
|
|
|
2015-06-12 03:34:20 +03:00
|
|
|
func getBlkioWeightDevices(config *runconfig.HostConfig) ([]*blkiodev.WeightDevice, error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2015-11-12 22:55:17 +03:00
|
|
|
func parseSecurityOpt(container *container.Container, config *runconfig.HostConfig) error {
|
2015-05-16 02:34:26 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-10-08 18:51:41 +03:00
|
|
|
func setupInitLayer(initLayer string, rootUID, rootGID int) error {
|
2015-05-16 02:34:26 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func checkKernel() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-07-31 01:28:11 +03:00
|
|
|
// adaptContainerSettings is called during container creation to modify any
|
|
|
|
// settings necessary in the HostConfig structure.
|
2015-12-02 05:53:52 +03:00
|
|
|
func (daemon *Daemon) adaptContainerSettings(hostConfig *runconfig.HostConfig, adjustCPUShares bool) error {
|
2015-09-24 22:10:41 +03:00
|
|
|
if hostConfig == nil {
|
2015-12-02 05:53:52 +03:00
|
|
|
return nil
|
2015-09-24 22:10:41 +03:00
|
|
|
}
|
|
|
|
|
2015-09-23 02:05:00 +03: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 05:53:52 +03:00
|
|
|
|
|
|
|
return nil
|
2015-07-13 10:17:43 +03:00
|
|
|
}
|
|
|
|
|
2015-07-31 01:28:11 +03:00
|
|
|
// verifyPlatformContainerSettings performs platform-specific validation of the
|
|
|
|
// hostconfig and config structures.
|
2015-09-29 20:51:40 +03:00
|
|
|
func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *runconfig.HostConfig, config *runconfig.Config) ([]string, error) {
|
2015-05-16 02:34:26 +03:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// checkConfigOptions checks for mutually incompatible config options
|
|
|
|
func checkConfigOptions(config *Config) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-07-11 22:32:08 +03:00
|
|
|
// checkSystem validates platform-specific requirements
|
2015-05-16 02:34:26 +03:00
|
|
|
func checkSystem() error {
|
|
|
|
// Validate the OS version. Note that docker.exe must be manifested for this
|
|
|
|
// call to return the correct version.
|
2015-10-15 21:40:14 +03:00
|
|
|
osv, err := system.GetOSVersion()
|
2015-05-16 02:34:26 +03:00
|
|
|
if err != nil {
|
2015-10-15 21:40:14 +03:00
|
|
|
return err
|
2015-05-16 02:34:26 +03:00
|
|
|
}
|
2015-10-15 21:40:14 +03:00
|
|
|
if osv.MajorVersion < 10 {
|
2015-05-16 02:34:26 +03:00
|
|
|
return fmt.Errorf("This version of Windows does not support the docker daemon")
|
|
|
|
}
|
2015-11-12 01:47:02 +03:00
|
|
|
if osv.Build < 10586 {
|
|
|
|
return fmt.Errorf("The Windows daemon requires Windows Server 2016 Technical Preview 4, build 10586 or later")
|
|
|
|
}
|
2015-05-16 02:34:26 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// configureKernelSecuritySupport configures and validate security support for the kernel
|
|
|
|
func configureKernelSecuritySupport(config *Config, driverName string) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func migrateIfDownlevel(driver graphdriver.Driver, root string) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-06-30 20:34:15 +03:00
|
|
|
func isBridgeNetworkDisabled(config *Config) bool {
|
2015-05-16 02:34:26 +03:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2015-09-21 15:04:36 +03:00
|
|
|
func (daemon *Daemon) initNetworkController(config *Config) (libnetwork.NetworkController, error) {
|
2015-07-13 22:34:58 +03:00
|
|
|
// Set the name of the virtual switch if not specified by -b on daemon start
|
|
|
|
if config.Bridge.VirtualSwitchName == "" {
|
2015-07-31 00:01:53 +03:00
|
|
|
config.Bridge.VirtualSwitchName = defaultVirtualSwitch
|
2015-07-13 22:34:58 +03:00
|
|
|
}
|
2015-05-16 02:34:26 +03:00
|
|
|
return nil, nil
|
|
|
|
}
|
2015-06-23 20:13:42 +03:00
|
|
|
|
2015-07-31 00:01:53 +03:00
|
|
|
// registerLinks sets up links between containers and writes the
|
2015-11-16 08:32:31 +03:00
|
|
|
// configuration out for persistence. As of Windows TP4, links are not supported.
|
2015-11-12 22:55:17 +03:00
|
|
|
func (daemon *Daemon) registerLinks(container *container.Container, hostConfig *runconfig.HostConfig) error {
|
2015-06-23 20:13:42 +03:00
|
|
|
return nil
|
|
|
|
}
|
2015-07-17 00:14:58 +03:00
|
|
|
|
2015-08-04 01:05:34 +03:00
|
|
|
func (daemon *Daemon) cleanupMounts() error {
|
|
|
|
return nil
|
|
|
|
}
|
2015-11-03 04:06:09 +03:00
|
|
|
|
|
|
|
// conditionalMountOnStart is a platform specific helper function during the
|
|
|
|
// container start to call mount.
|
2015-11-12 22:55:17 +03:00
|
|
|
func (daemon *Daemon) conditionalMountOnStart(container *container.Container) error {
|
2015-11-03 04:06:09 +03:00
|
|
|
// We do not mount if a Hyper-V container
|
2015-11-12 22:55:17 +03:00
|
|
|
if !container.HostConfig.Isolation.IsHyperV() {
|
2015-11-03 04:06:09 +03:00
|
|
|
if err := daemon.Mount(container); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// conditionalUnmountOnCleanup is a platform specific helper function called
|
|
|
|
// during the cleanup of a container to unmount.
|
2015-11-12 22:55:17 +03:00
|
|
|
func (daemon *Daemon) conditionalUnmountOnCleanup(container *container.Container) {
|
2015-11-03 04:06:09 +03:00
|
|
|
// We do not unmount if a Hyper-V container
|
2015-11-12 22:55:17 +03:00
|
|
|
if !container.HostConfig.Isolation.IsHyperV() {
|
2015-11-19 01:20:54 +03:00
|
|
|
daemon.Unmount(container)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func restoreCustomImage(driver graphdriver.Driver, is image.Store, ls layer.Store, ts tag.Store) error {
|
|
|
|
if wd, ok := driver.(*windows.Driver); ok {
|
|
|
|
imageInfos, err := wd.GetCustomImageInfos()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2015-11-03 04:06:09 +03:00
|
|
|
}
|
2015-11-19 01:20:54 +03:00
|
|
|
|
|
|
|
// Convert imageData to valid image configuration
|
|
|
|
for i := range imageInfos {
|
|
|
|
name := strings.ToLower(imageInfos[i].Name)
|
|
|
|
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
if _, err := r.RegisterDiffID(imageInfos[i].ID, imageInfos[i].Size); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// layer is intentionally not released
|
|
|
|
|
|
|
|
rootFS := image.NewRootFS()
|
|
|
|
rootFS.BaseLayer = filepath.Base(imageInfos[i].Path)
|
|
|
|
|
|
|
|
// Create history for base layer
|
|
|
|
config, err := json.Marshal(&image.Image{
|
|
|
|
V1Image: image.V1Image{
|
|
|
|
DockerVersion: dockerversion.Version,
|
|
|
|
Architecture: runtime.GOARCH,
|
|
|
|
OS: runtime.GOOS,
|
|
|
|
Created: imageInfos[i].CreatedTime,
|
|
|
|
},
|
|
|
|
RootFS: rootFS,
|
|
|
|
History: []image.History{},
|
|
|
|
})
|
|
|
|
|
|
|
|
named, err := reference.ParseNamed(name)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
ref, err := reference.WithTag(named, imageInfos[i].Version)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
id, err := is.Create(config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-11-25 23:42:40 +03:00
|
|
|
if err := ts.AddTag(ref, id, true); err != nil {
|
2015-11-19 01:20:54 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
logrus.Debugf("Registered base layer %s as %s", ref, id)
|
|
|
|
}
|
|
|
|
|
2015-11-03 04:06:09 +03:00
|
|
|
}
|
2015-11-19 01:20:54 +03:00
|
|
|
|
|
|
|
return nil
|
2015-11-03 04:06:09 +03:00
|
|
|
}
|