github.com/vieux/docker@v0.6.3-0.20161004191708-e097c2a938c7/container/container_windows.go (about)

     1  // +build windows
     2  
     3  package container
     4  
     5  import (
     6  	"fmt"
     7  	"os"
     8  	"path/filepath"
     9  
    10  	containertypes "github.com/docker/docker/api/types/container"
    11  	"github.com/docker/docker/utils"
    12  	"github.com/docker/docker/volume"
    13  )
    14  
    15  // Container holds fields specific to the Windows implementation. See
    16  // CommonContainer for standard fields common to all containers.
    17  type Container struct {
    18  	CommonContainer
    19  
    20  	HostnamePath   string
    21  	HostsPath      string
    22  	ResolvConfPath string
    23  	// Fields below here are platform specific.
    24  }
    25  
    26  // ExitStatus provides exit reasons for a container.
    27  type ExitStatus struct {
    28  	// The exit code with which the container exited.
    29  	ExitCode int
    30  }
    31  
    32  // CreateDaemonEnvironment creates a new environment variable slice for this container.
    33  func (container *Container) CreateDaemonEnvironment(_ bool, linkedEnv []string) []string {
    34  	// because the env on the container can override certain default values
    35  	// we need to replace the 'env' keys where they match and append anything
    36  	// else.
    37  	return utils.ReplaceOrAppendEnvValues(linkedEnv, container.Config.Env)
    38  }
    39  
    40  // UnmountIpcMounts unmounts Ipc related mounts.
    41  // This is a NOOP on windows.
    42  func (container *Container) UnmountIpcMounts(unmount func(pth string) error) {
    43  }
    44  
    45  // IpcMounts returns the list of Ipc related mounts.
    46  func (container *Container) IpcMounts() []Mount {
    47  	return nil
    48  }
    49  
    50  // UnmountVolumes explicitly unmounts volumes from the container.
    51  func (container *Container) UnmountVolumes(forceSyscall bool, volumeEventLog func(name, action string, attributes map[string]string)) error {
    52  	var (
    53  		volumeMounts []volume.MountPoint
    54  		err          error
    55  	)
    56  
    57  	for _, mntPoint := range container.MountPoints {
    58  		// Do not attempt to get the mountpoint destination on the host as it
    59  		// is not accessible on Windows in the case that a container is running.
    60  		// (It's a special reparse point which doesn't have any contextual meaning).
    61  		volumeMounts = append(volumeMounts, volume.MountPoint{Volume: mntPoint.Volume, ID: mntPoint.ID})
    62  	}
    63  
    64  	// atm, this is a no-op.
    65  	if volumeMounts, err = appendNetworkMounts(container, volumeMounts); err != nil {
    66  		return err
    67  	}
    68  
    69  	for _, volumeMount := range volumeMounts {
    70  		if volumeMount.Volume != nil {
    71  			if err := volumeMount.Volume.Unmount(volumeMount.ID); err != nil {
    72  				return err
    73  			}
    74  			volumeMount.ID = ""
    75  
    76  			attributes := map[string]string{
    77  				"driver":    volumeMount.Volume.DriverName(),
    78  				"container": container.ID,
    79  			}
    80  			volumeEventLog(volumeMount.Volume.Name(), "unmount", attributes)
    81  		}
    82  	}
    83  
    84  	return nil
    85  }
    86  
    87  // TmpfsMounts returns the list of tmpfs mounts
    88  func (container *Container) TmpfsMounts() []Mount {
    89  	var mounts []Mount
    90  	return mounts
    91  }
    92  
    93  // UpdateContainer updates configuration of a container
    94  func (container *Container) UpdateContainer(hostConfig *containertypes.HostConfig) error {
    95  	container.Lock()
    96  	defer container.Unlock()
    97  	resources := hostConfig.Resources
    98  	if resources.BlkioWeight != 0 || resources.CPUShares != 0 ||
    99  		resources.CPUPeriod != 0 || resources.CPUQuota != 0 ||
   100  		resources.CpusetCpus != "" || resources.CpusetMems != "" ||
   101  		resources.Memory != 0 || resources.MemorySwap != 0 ||
   102  		resources.MemoryReservation != 0 || resources.KernelMemory != 0 {
   103  		return fmt.Errorf("Resource updating isn't supported on Windows")
   104  	}
   105  	// update HostConfig of container
   106  	if hostConfig.RestartPolicy.Name != "" {
   107  		if container.HostConfig.AutoRemove && !hostConfig.RestartPolicy.IsNone() {
   108  			return fmt.Errorf("Restart policy cannot be updated because AutoRemove is enabled for the container")
   109  		}
   110  		container.HostConfig.RestartPolicy = hostConfig.RestartPolicy
   111  	}
   112  	return nil
   113  }
   114  
   115  // appendNetworkMounts appends any network mounts to the array of mount points passed in.
   116  // Windows does not support network mounts (not to be confused with SMB network mounts), so
   117  // this is a no-op.
   118  func appendNetworkMounts(container *Container, volumeMounts []volume.MountPoint) ([]volume.MountPoint, error) {
   119  	return volumeMounts, nil
   120  }
   121  
   122  // cleanResourcePath cleans a resource path by removing C:\ syntax, and prepares
   123  // to combine with a volume path
   124  func cleanResourcePath(path string) string {
   125  	if len(path) >= 2 {
   126  		c := path[0]
   127  		if path[1] == ':' && ('a' <= c && c <= 'z' || 'A' <= c && c <= 'Z') {
   128  			path = path[2:]
   129  		}
   130  	}
   131  	return filepath.Join(string(os.PathSeparator), path)
   132  }
   133  
   134  // BuildHostnameFile writes the container's hostname file.
   135  func (container *Container) BuildHostnameFile() error {
   136  	return nil
   137  }
   138  
   139  // canMountFS determines if the file system for the container
   140  // can be mounted locally. In the case of Windows, this is not possible
   141  // for Hyper-V containers during WORKDIR execution for example.
   142  func (container *Container) canMountFS() bool {
   143  	return !containertypes.Isolation.IsHyperV(container.HostConfig.Isolation)
   144  }
   145  
   146  // EnableServiceDiscoveryOnDefaultNetwork Enable service discovery on default network
   147  func (container *Container) EnableServiceDiscoveryOnDefaultNetwork() bool {
   148  	return true
   149  }