2015-04-29 18:53:35 -04:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2015-06-11 14:29:29 -04:00
|
|
|
"path/filepath"
|
2015-04-29 18:53:35 -04:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/docker/docker/daemon/execdriver"
|
2015-06-11 14:29:29 -04:00
|
|
|
"github.com/docker/docker/daemon/graphdriver/windows"
|
2015-07-20 13:57:15 -04:00
|
|
|
"github.com/docker/docker/image"
|
2015-04-29 18:53:35 -04:00
|
|
|
"github.com/docker/docker/pkg/archive"
|
2015-06-11 14:29:29 -04:00
|
|
|
"github.com/microsoft/hcsshim"
|
2015-04-29 18:53:35 -04:00
|
|
|
)
|
|
|
|
|
2015-06-01 19:42:27 -04:00
|
|
|
// This is deliberately empty on Windows as the default path will be set by
|
|
|
|
// the container. Docker has no context of what the default path should be.
|
|
|
|
const DefaultPathEnv = ""
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
func (container *Container) setupContainerDns() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (container *Container) updateParentsHosts() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (container *Container) setupLinkedContainers() ([]string, error) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
func (container *Container) initializeNetworking() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (container *Container) setupWorkingDirectory() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func populateCommand(c *Container, env []string) error {
|
|
|
|
en := &execdriver.Network{
|
|
|
|
Mtu: c.daemon.config.Mtu,
|
|
|
|
Interface: nil,
|
|
|
|
}
|
|
|
|
|
|
|
|
parts := strings.SplitN(string(c.hostConfig.NetworkMode), ":", 2)
|
|
|
|
switch parts[0] {
|
2015-06-23 13:13:42 -04:00
|
|
|
|
2015-04-29 18:53:35 -04:00
|
|
|
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-07-16 16:20:14 -04:00
|
|
|
MacAddress: c.Config.MacAddress,
|
2015-07-13 15:34:58 -04:00
|
|
|
Bridge: c.daemon.config.Bridge.VirtualSwitchName,
|
2015-04-29 18:53:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return fmt.Errorf("invalid network mode: %s", c.hostConfig.NetworkMode)
|
|
|
|
}
|
|
|
|
|
|
|
|
pid := &execdriver.Pid{}
|
|
|
|
|
|
|
|
// TODO Windows. This can probably be factored out.
|
|
|
|
pid.HostPid = c.hostConfig.PidMode.IsHost()
|
|
|
|
|
|
|
|
// TODO Windows. Resource controls to be implemented later.
|
|
|
|
resources := &execdriver.Resources{}
|
|
|
|
|
|
|
|
// 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 layerFolder string
|
|
|
|
var layerPaths []string
|
|
|
|
|
|
|
|
// The following is specific to the Windows driver. We do this to
|
|
|
|
// enable VFS to continue operating for development purposes.
|
|
|
|
if wd, ok := c.daemon.driver.(*windows.WindowsGraphDriver); ok {
|
|
|
|
var err error
|
2015-07-20 13:57:15 -04:00
|
|
|
var img *image.Image
|
2015-06-11 14:29:29 -04:00
|
|
|
var ids []string
|
|
|
|
|
|
|
|
if img, err = c.daemon.graph.Get(c.ImageID); err != nil {
|
|
|
|
return fmt.Errorf("Failed to graph.Get on ImageID %s - %s", c.ImageID, err)
|
|
|
|
}
|
|
|
|
if ids, err = c.daemon.graph.ParentLayerIds(img); err != nil {
|
|
|
|
return fmt.Errorf("Failed to get parentlayer ids %s", img.ID)
|
|
|
|
}
|
|
|
|
layerPaths = wd.LayerIdsToPaths(ids)
|
|
|
|
layerFolder = filepath.Join(wd.Info().HomeDir, filepath.Base(c.ID))
|
|
|
|
}
|
|
|
|
|
2015-04-29 18:53:35 -04:00
|
|
|
// TODO Windows: Factor out remainder of unused fields.
|
|
|
|
c.command = &execdriver.Command{
|
|
|
|
ID: c.ID,
|
|
|
|
Rootfs: c.RootfsPath(),
|
|
|
|
ReadonlyRootfs: c.hostConfig.ReadonlyRootfs,
|
|
|
|
InitPath: "/.dockerinit",
|
|
|
|
WorkingDir: c.Config.WorkingDir,
|
|
|
|
Network: en,
|
|
|
|
Pid: pid,
|
|
|
|
Resources: resources,
|
2015-07-01 13:59:18 -04:00
|
|
|
CapAdd: c.hostConfig.CapAdd.Slice(),
|
|
|
|
CapDrop: c.hostConfig.CapDrop.Slice(),
|
2015-04-29 18:53:35 -04:00
|
|
|
ProcessConfig: processConfig,
|
|
|
|
ProcessLabel: c.GetProcessLabel(),
|
|
|
|
MountLabel: c.GetMountLabel(),
|
2015-05-27 16:15:14 -04:00
|
|
|
FirstStart: !c.HasBeenStartedBefore,
|
2015-06-11 14:29:29 -04:00
|
|
|
LayerFolder: layerFolder,
|
|
|
|
LayerPaths: layerPaths,
|
2015-04-29 18:53:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetSize, return real size, virtual size
|
|
|
|
func (container *Container) GetSize() (int64, int64) {
|
|
|
|
// TODO Windows
|
|
|
|
return 0, 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func (container *Container) AllocateNetwork() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (container *Container) ExportRw() (archive.Archive, error) {
|
|
|
|
if container.IsRunning() {
|
|
|
|
return nil, fmt.Errorf("Cannot export a running container.")
|
|
|
|
}
|
|
|
|
// TODO Windows. Implementation (different to Linux)
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2015-07-20 18:19:05 -04:00
|
|
|
func (container *Container) UpdateNetwork() error {
|
2015-04-29 18:53:35 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-07-20 18:19:05 -04:00
|
|
|
func (container *Container) ReleaseNetwork() {
|
2015-04-29 18:53:35 -04:00
|
|
|
}
|
|
|
|
|
2015-07-20 18:19:05 -04:00
|
|
|
func (container *Container) RestoreNetwork() error {
|
|
|
|
return nil
|
2015-04-29 18:53:35 -04:00
|
|
|
}
|
2015-05-26 12:33:55 -04:00
|
|
|
|
|
|
|
func (container *Container) UnmountVolumes(forceSyscall bool) error {
|
|
|
|
return nil
|
|
|
|
}
|
2015-06-11 14:29:29 -04:00
|
|
|
|
|
|
|
func (container *Container) PrepareStorage() error {
|
|
|
|
if wd, ok := container.daemon.driver.(*windows.WindowsGraphDriver); ok {
|
|
|
|
// Get list of paths to parent layers.
|
|
|
|
var ids []string
|
|
|
|
if container.ImageID != "" {
|
|
|
|
img, err := container.daemon.graph.Get(container.ImageID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
ids, err = container.daemon.graph.ParentLayerIds(img)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := hcsshim.PrepareLayer(wd.Info(), container.ID, wd.LayerIdsToPaths(ids)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (container *Container) CleanupStorage() error {
|
|
|
|
if wd, ok := container.daemon.driver.(*windows.WindowsGraphDriver); ok {
|
|
|
|
return hcsshim.UnprepareLayer(wd.Info(), container.ID)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2015-07-16 17:14:58 -04:00
|
|
|
|
2015-07-30 17:46:51 -04:00
|
|
|
// prepareMountPoints is a no-op on Windows
|
2015-07-16 17:14:58 -04:00
|
|
|
func (container *Container) prepareMountPoints() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-07-30 17:46:51 -04:00
|
|
|
// removeMountPoints is a no-op on Windows.
|
2015-07-16 17:14:58 -04:00
|
|
|
func (container *Container) removeMountPoints() error {
|
|
|
|
return nil
|
|
|
|
}
|