2015-04-29 18:53:35 -04:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
2015-09-18 21:21:57 -04:00
|
|
|
"github.com/Sirupsen/logrus"
|
2015-04-29 18:53:35 -04:00
|
|
|
"github.com/docker/docker/daemon/execdriver"
|
2015-09-17 14:54:14 -04:00
|
|
|
derr "github.com/docker/docker/errors"
|
2015-09-09 22:23:06 -04:00
|
|
|
"github.com/docker/docker/volume"
|
2015-09-25 06:19:17 -04:00
|
|
|
"github.com/docker/libnetwork"
|
2015-04-29 18:53:35 -04:00
|
|
|
)
|
|
|
|
|
2015-07-30 17:01:53 -04:00
|
|
|
// DefaultPathEnv is deliberately empty on Windows as the default path will be set by
|
2015-06-01 19:42:27 -04:00
|
|
|
// the container. Docker has no context of what the default path should be.
|
|
|
|
const DefaultPathEnv = ""
|
2015-04-29 18:53:35 -04:00
|
|
|
|
2015-07-30 17:01:53 -04:00
|
|
|
// Container holds fields specific to the Windows implementation. See
|
|
|
|
// CommonContainer for standard fields common to all containers.
|
2015-04-29 18:53:35 -04:00
|
|
|
type Container struct {
|
|
|
|
CommonContainer
|
|
|
|
|
|
|
|
// Fields below here are platform specific.
|
|
|
|
}
|
|
|
|
|
|
|
|
func killProcessDirectly(container *Container) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:51:40 -04:00
|
|
|
func (container *Container) setupLinkedContainers() ([]string, error) {
|
2015-04-29 18:53:35 -04:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (container *Container) createDaemonEnvironment(linkedEnv []string) []string {
|
2015-06-01 19:42:27 -04:00
|
|
|
// On Windows, nothing to link. Just return the container environment.
|
|
|
|
return container.Config.Env
|
2015-04-29 18:53:35 -04:00
|
|
|
}
|
|
|
|
|
2015-09-29 13:51:40 -04:00
|
|
|
func (container *Container) initializeNetworking() error {
|
2015-04-29 18:53:35 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-09-25 06:19:17 -04:00
|
|
|
// ConnectToNetwork connects a container to the network
|
|
|
|
func (container *Container) ConnectToNetwork(idOrName string) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// DisconnectFromNetwork disconnects a container from, the network
|
|
|
|
func (container *Container) DisconnectFromNetwork(n libnetwork.Network) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-04-29 18:53:35 -04:00
|
|
|
func (container *Container) setupWorkingDirectory() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:51:40 -04:00
|
|
|
func populateCommand(c *Container, env []string) error {
|
2015-04-29 18:53:35 -04:00
|
|
|
en := &execdriver.Network{
|
|
|
|
Interface: nil,
|
|
|
|
}
|
|
|
|
|
|
|
|
parts := strings.SplitN(string(c.hostConfig.NetworkMode), ":", 2)
|
|
|
|
switch parts[0] {
|
|
|
|
case "none":
|
2015-06-23 13:13:42 -04:00
|
|
|
case "default", "": // empty string to support existing containers
|
2015-04-29 18:53:35 -04:00
|
|
|
if !c.Config.NetworkDisabled {
|
|
|
|
en.Interface = &execdriver.NetworkInterface{
|
2015-08-06 22:21:00 -04:00
|
|
|
MacAddress: c.Config.MacAddress,
|
2015-07-30 17:01:53 -04:00
|
|
|
Bridge: c.daemon.configStore.Bridge.VirtualSwitchName,
|
2015-08-06 22:21:00 -04:00
|
|
|
PortBindings: c.hostConfig.PortBindings,
|
|
|
|
|
|
|
|
// TODO Windows. Include IPAddress. There already is a
|
|
|
|
// property IPAddress on execDrive.CommonNetworkInterface,
|
|
|
|
// but there is no CLI option in docker to pass through
|
|
|
|
// an IPAddress on docker run.
|
2015-04-29 18:53:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
default:
|
2015-09-16 14:56:26 -04:00
|
|
|
return derr.ErrorCodeInvalidNetworkMode.WithArgs(c.hostConfig.NetworkMode)
|
2015-04-29 18:53:35 -04:00
|
|
|
}
|
|
|
|
|
2015-09-22 19:05:00 -04:00
|
|
|
// TODO Windows. More resource controls to be implemented later.
|
|
|
|
resources := &execdriver.Resources{
|
2015-10-05 13:11:10 -04:00
|
|
|
CommonResources: execdriver.CommonResources{
|
|
|
|
CPUShares: c.hostConfig.CPUShares,
|
|
|
|
},
|
2015-09-22 19:05:00 -04:00
|
|
|
}
|
2015-04-29 18:53:35 -04:00
|
|
|
|
|
|
|
// TODO Windows. Further refactoring required (privileged/user)
|
|
|
|
processConfig := execdriver.ProcessConfig{
|
2015-05-27 16:15:14 -04:00
|
|
|
Privileged: c.hostConfig.Privileged,
|
|
|
|
Entrypoint: c.Path,
|
|
|
|
Arguments: c.Args,
|
|
|
|
Tty: c.Config.Tty,
|
|
|
|
User: c.Config.User,
|
|
|
|
ConsoleSize: c.hostConfig.ConsoleSize,
|
2015-04-29 18:53:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
processConfig.Env = env
|
|
|
|
|
2015-06-11 14:29:29 -04:00
|
|
|
var layerPaths []string
|
2015-07-24 20:49:43 -04:00
|
|
|
img, err := c.daemon.graph.Get(c.ImageID)
|
|
|
|
if err != nil {
|
2015-09-16 14:56:26 -04:00
|
|
|
return derr.ErrorCodeGetGraph.WithArgs(c.ImageID, err)
|
2015-07-24 20:49:43 -04:00
|
|
|
}
|
|
|
|
for i := img; i != nil && err == nil; i, err = c.daemon.graph.GetParent(i) {
|
|
|
|
lp, err := c.daemon.driver.Get(i.ID, "")
|
|
|
|
if err != nil {
|
2015-09-16 14:56:26 -04:00
|
|
|
return derr.ErrorCodeGetLayer.WithArgs(c.daemon.driver.String(), i.ID, err)
|
2015-06-11 14:29:29 -04:00
|
|
|
}
|
2015-07-24 20:49:43 -04:00
|
|
|
layerPaths = append(layerPaths, lp)
|
|
|
|
err = c.daemon.driver.Put(i.ID)
|
|
|
|
if err != nil {
|
2015-09-16 14:56:26 -04:00
|
|
|
return derr.ErrorCodePutLayer.WithArgs(c.daemon.driver.String(), i.ID, err)
|
2015-06-11 14:29:29 -04:00
|
|
|
}
|
|
|
|
}
|
2015-07-24 20:49:43 -04:00
|
|
|
m, err := c.daemon.driver.GetMetadata(c.ID)
|
|
|
|
if err != nil {
|
2015-09-16 14:56:26 -04:00
|
|
|
return derr.ErrorCodeGetLayerMetadata.WithArgs(err)
|
2015-07-24 20:49:43 -04:00
|
|
|
}
|
|
|
|
layerFolder := m["dir"]
|
2015-06-11 14:29:29 -04:00
|
|
|
|
2015-04-29 18:53:35 -04:00
|
|
|
c.command = &execdriver.Command{
|
2015-10-05 17:27:39 -04:00
|
|
|
CommonCommand: execdriver.CommonCommand{
|
|
|
|
ID: c.ID,
|
|
|
|
Rootfs: c.rootfsPath(),
|
|
|
|
InitPath: "/.dockerinit",
|
|
|
|
WorkingDir: c.Config.WorkingDir,
|
|
|
|
Network: en,
|
|
|
|
MountLabel: c.getMountLabel(),
|
|
|
|
Resources: resources,
|
|
|
|
ProcessConfig: processConfig,
|
|
|
|
ProcessLabel: c.getProcessLabel(),
|
|
|
|
},
|
|
|
|
FirstStart: !c.HasBeenStartedBefore,
|
|
|
|
LayerFolder: layerFolder,
|
|
|
|
LayerPaths: layerPaths,
|
|
|
|
Hostname: c.Config.Hostname,
|
|
|
|
Isolated: c.hostConfig.Isolation.IsHyperV(),
|
2015-04-29 18:53:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-07-30 17:01:53 -04:00
|
|
|
// GetSize returns real size & virtual size
|
2015-09-29 13:51:40 -04:00
|
|
|
func (container *Container) getSize() (int64, int64) {
|
2015-04-29 18:53:35 -04:00
|
|
|
// TODO Windows
|
|
|
|
return 0, 0
|
|
|
|
}
|
|
|
|
|
2015-09-11 15:05:57 -04:00
|
|
|
// setNetworkNamespaceKey is a no-op on Windows.
|
|
|
|
func (container *Container) setNetworkNamespaceKey(pid int) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-07-30 17:01:53 -04:00
|
|
|
// allocateNetwork is a no-op on Windows.
|
|
|
|
func (container *Container) allocateNetwork() error {
|
2015-04-29 18:53:35 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:51:40 -04:00
|
|
|
func (container *Container) updateNetwork() error {
|
2015-07-30 17:01:53 -04:00
|
|
|
return nil
|
2015-04-29 18:53:35 -04:00
|
|
|
}
|
|
|
|
|
2015-07-30 17:01:53 -04:00
|
|
|
func (container *Container) releaseNetwork() {
|
2015-04-29 18:53:35 -04:00
|
|
|
}
|
2015-05-26 12:33:55 -04:00
|
|
|
|
2015-09-09 22:23:06 -04:00
|
|
|
// appendNetworkMounts appends any network mounts to the array of mount points passed in.
|
|
|
|
// Windows does not support network mounts (not to be confused with SMB network mounts), so
|
|
|
|
// this is a no-op.
|
|
|
|
func appendNetworkMounts(container *Container, volumeMounts []volume.MountPoint) ([]volume.MountPoint, error) {
|
|
|
|
return volumeMounts, nil
|
2015-07-16 17:14:58 -04:00
|
|
|
}
|
2015-08-03 18:05:34 -04:00
|
|
|
|
|
|
|
func (container *Container) setupIpcDirs() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-10-30 19:00:01 -04:00
|
|
|
func (container *Container) unmountIpcMounts(unmount func(pth string) error) {
|
2015-10-30 14:55:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func detachMounted(path string) error {
|
2015-08-03 18:05:34 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (container *Container) ipcMounts() []execdriver.Mount {
|
|
|
|
return nil
|
|
|
|
}
|
2015-09-24 17:59:23 -04:00
|
|
|
|
|
|
|
func getDefaultRouteMtu() (int, error) {
|
|
|
|
return -1, errSystemNotSupported
|
|
|
|
}
|
2015-09-18 21:21:57 -04:00
|
|
|
|
|
|
|
// conditionalMountOnStart is a platform specific helper function during the
|
|
|
|
// container start to call mount.
|
|
|
|
func (container *Container) conditionalMountOnStart() error {
|
|
|
|
// We do not mount if a Hyper-V container
|
|
|
|
if !container.hostConfig.Isolation.IsHyperV() {
|
|
|
|
if err := container.Mount(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// conditionalUnmountOnCleanup is a platform specific helper function called
|
|
|
|
// during the cleanup of a container to unmount.
|
|
|
|
func (container *Container) conditionalUnmountOnCleanup() {
|
|
|
|
// We do not unmount if a Hyper-V container
|
|
|
|
if !container.hostConfig.Isolation.IsHyperV() {
|
|
|
|
if err := container.Unmount(); err != nil {
|
|
|
|
logrus.Errorf("%v: Failed to umount filesystem: %v", container.ID, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|