github.com/jingleWang/moby@v1.13.1/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  )
    13  
    14  // Container holds fields specific to the Windows implementation. See
    15  // CommonContainer for standard fields common to all containers.
    16  type Container struct {
    17  	CommonContainer
    18  
    19  	// Fields below here are platform specific.
    20  }
    21  
    22  // ExitStatus provides exit reasons for a container.
    23  type ExitStatus struct {
    24  	// The exit code with which the container exited.
    25  	ExitCode int
    26  }
    27  
    28  // CreateDaemonEnvironment creates a new environment variable slice for this container.
    29  func (container *Container) CreateDaemonEnvironment(_ bool, linkedEnv []string) []string {
    30  	// because the env on the container can override certain default values
    31  	// we need to replace the 'env' keys where they match and append anything
    32  	// else.
    33  	return utils.ReplaceOrAppendEnvValues(linkedEnv, container.Config.Env)
    34  }
    35  
    36  // UnmountIpcMounts unmounts Ipc related mounts.
    37  // This is a NOOP on windows.
    38  func (container *Container) UnmountIpcMounts(unmount func(pth string) error) {
    39  }
    40  
    41  // IpcMounts returns the list of Ipc related mounts.
    42  func (container *Container) IpcMounts() []Mount {
    43  	return nil
    44  }
    45  
    46  // SecretMount returns the mount for the secret path
    47  func (container *Container) SecretMount() *Mount {
    48  	return nil
    49  }
    50  
    51  // UnmountSecrets unmounts the fs for secrets
    52  func (container *Container) UnmountSecrets() error {
    53  	return nil
    54  }
    55  
    56  // DetachAndUnmount unmounts all volumes.
    57  // On Windows it only delegates to `UnmountVolumes` since there is nothing to
    58  // force unmount.
    59  func (container *Container) DetachAndUnmount(volumeEventLog func(name, action string, attributes map[string]string)) error {
    60  	return container.UnmountVolumes(volumeEventLog)
    61  }
    62  
    63  // TmpfsMounts returns the list of tmpfs mounts
    64  func (container *Container) TmpfsMounts() ([]Mount, error) {
    65  	var mounts []Mount
    66  	return mounts, nil
    67  }
    68  
    69  // UpdateContainer updates configuration of a container
    70  func (container *Container) UpdateContainer(hostConfig *containertypes.HostConfig) error {
    71  	container.Lock()
    72  	defer container.Unlock()
    73  	resources := hostConfig.Resources
    74  	if resources.BlkioWeight != 0 || resources.CPUShares != 0 ||
    75  		resources.CPUPeriod != 0 || resources.CPUQuota != 0 ||
    76  		resources.CpusetCpus != "" || resources.CpusetMems != "" ||
    77  		resources.Memory != 0 || resources.MemorySwap != 0 ||
    78  		resources.MemoryReservation != 0 || resources.KernelMemory != 0 {
    79  		return fmt.Errorf("Resource updating isn't supported on Windows")
    80  	}
    81  	// update HostConfig of container
    82  	if hostConfig.RestartPolicy.Name != "" {
    83  		if container.HostConfig.AutoRemove && !hostConfig.RestartPolicy.IsNone() {
    84  			return fmt.Errorf("Restart policy cannot be updated because AutoRemove is enabled for the container")
    85  		}
    86  		container.HostConfig.RestartPolicy = hostConfig.RestartPolicy
    87  	}
    88  	return nil
    89  }
    90  
    91  // cleanResourcePath cleans a resource path by removing C:\ syntax, and prepares
    92  // to combine with a volume path
    93  func cleanResourcePath(path string) string {
    94  	if len(path) >= 2 {
    95  		c := path[0]
    96  		if path[1] == ':' && ('a' <= c && c <= 'z' || 'A' <= c && c <= 'Z') {
    97  			path = path[2:]
    98  		}
    99  	}
   100  	return filepath.Join(string(os.PathSeparator), path)
   101  }
   102  
   103  // BuildHostnameFile writes the container's hostname file.
   104  func (container *Container) BuildHostnameFile() error {
   105  	return nil
   106  }
   107  
   108  // EnableServiceDiscoveryOnDefaultNetwork Enable service discovery on default network
   109  func (container *Container) EnableServiceDiscoveryOnDefaultNetwork() bool {
   110  	return true
   111  }