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
|
|
|
|
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"
|
2015-11-18 22:20:54 +00:00
|
|
|
"github.com/docker/docker/dockerversion"
|
|
|
|
"github.com/docker/docker/image"
|
|
|
|
"github.com/docker/docker/layer"
|
2015-12-04 21:55:15 +00:00
|
|
|
"github.com/docker/docker/reference"
|
2016-01-05 00:05:26 +00:00
|
|
|
containertypes "github.com/docker/engine-api/types/container"
|
2015-07-30 21:01:53 +00:00
|
|
|
// register the windows graph driver
|
2015-11-18 22:20:54 +00:00
|
|
|
"github.com/docker/docker/daemon/graphdriver/windows"
|
2016-01-08 03:43:11 +00:00
|
|
|
"github.com/docker/docker/pkg/idtools"
|
2015-10-15 18:40:14 +00:00
|
|
|
"github.com/docker/docker/pkg/system"
|
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"
|
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 (
|
2015-07-30 21:01:53 +00:00
|
|
|
defaultVirtualSwitch = "Virtual Switch"
|
2015-08-07 16:33:29 +00:00
|
|
|
platformSupported = true
|
2015-09-22 23:05:00 +00:00
|
|
|
windowsMinCPUShares = 1
|
2015-11-12 18:58:20 +00:00
|
|
|
windowsMaxCPUShares = 10000
|
2015-08-07 16:33:29 +00:00
|
|
|
)
|
2015-07-13 19:34:58 +00:00
|
|
|
|
2015-12-18 18:36:17 +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
|
|
|
|
}
|
|
|
|
|
2015-12-18 18:36:17 +00:00
|
|
|
func getBlkioReadIOpsDevices(config *containertypes.HostConfig) ([]*blkiodev.ThrottleDevice, error) {
|
2015-07-08 11:06:48 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2015-12-18 18:36:17 +00:00
|
|
|
func getBlkioWriteIOpsDevices(config *containertypes.HostConfig) ([]*blkiodev.ThrottleDevice, error) {
|
2015-07-08 11:06:48 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2015-12-18 18:36:17 +00:00
|
|
|
func getBlkioReadBpsDevices(config *containertypes.HostConfig) ([]*blkiodev.ThrottleDevice, error) {
|
2015-07-08 11:06:48 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2015-12-18 18:36:17 +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
|
|
|
}
|
|
|
|
|
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) {
|
2015-05-15 23:34:26 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
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.
|
2015-10-15 18:40:14 +00:00
|
|
|
osv, err := system.GetOSVersion()
|
2015-05-15 23:34:26 +00:00
|
|
|
if err != nil {
|
2015-10-15 18:40:14 +00:00
|
|
|
return err
|
2015-05-15 23:34:26 +00:00
|
|
|
}
|
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")
|
|
|
|
}
|
2015-11-11 22:47:02 +00:00
|
|
|
if osv.Build < 10586 {
|
|
|
|
return fmt.Errorf("The Windows daemon requires Windows Server 2016 Technical Preview 4, build 10586 or later")
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
2015-06-30 17:34:15 +00:00
|
|
|
func isBridgeNetworkDisabled(config *Config) bool {
|
2015-05-15 23:34:26 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2015-09-21 12:04:36 +00:00
|
|
|
func (daemon *Daemon) initNetworkController(config *Config) (libnetwork.NetworkController, error) {
|
2015-07-13 19:34:58 +00:00
|
|
|
// Set the name of the virtual switch if not specified by -b on daemon start
|
2016-01-25 21:30:33 +00:00
|
|
|
if config.bridgeConfig.VirtualSwitchName == "" {
|
|
|
|
config.bridgeConfig.VirtualSwitchName = defaultVirtualSwitch
|
2015-07-13 19:34:58 +00:00
|
|
|
}
|
2015-05-15 23:34:26 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
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
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2015-11-03 01:06:09 +00:00
|
|
|
// conditionalMountOnStart is a platform specific helper function during the
|
|
|
|
// container start to call mount.
|
2015-11-12 19:55:17 +00:00
|
|
|
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
|
2015-11-12 19:55:17 +00:00
|
|
|
if !container.HostConfig.Isolation.IsHyperV() {
|
2015-11-03 01:06:09 +00: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 19:55:17 +00:00
|
|
|
func (daemon *Daemon) conditionalUnmountOnCleanup(container *container.Container) {
|
2015-11-03 01:06:09 +00:00
|
|
|
// We do not unmount if a Hyper-V container
|
2015-11-12 19:55:17 +00:00
|
|
|
if !container.HostConfig.Isolation.IsHyperV() {
|
2015-11-18 22:20:54 +00:00
|
|
|
daemon.Unmount(container)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
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)
|
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
|
|
|
|
2015-12-16 20:32:16 +00:00
|
|
|
ref, err := reference.WithTag(named, imageInfos[i].Version)
|
|
|
|
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 {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
func (daemon *Daemon) networkOptions(dconfig *Config) ([]nwconfig.Option, error) {
|
|
|
|
return nil, fmt.Errorf("Network controller config reload not aavailable on Windows yet")
|
|
|
|
}
|