2015-11-12 14:55:17 -05:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
2016-01-04 10:58:20 -05:00
|
|
|
"fmt"
|
2016-01-27 16:03:09 -05:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
2016-09-06 14:18:12 -04:00
|
|
|
containertypes "github.com/docker/docker/api/types/container"
|
2016-05-04 14:06:54 -04:00
|
|
|
"github.com/docker/docker/utils"
|
2015-11-12 14:55:17 -05:00
|
|
|
"github.com/docker/docker/volume"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Container holds fields specific to the Windows implementation. See
|
|
|
|
// CommonContainer for standard fields common to all containers.
|
|
|
|
type Container struct {
|
|
|
|
CommonContainer
|
|
|
|
|
2016-03-09 23:33:21 -05:00
|
|
|
HostnamePath string
|
|
|
|
HostsPath string
|
|
|
|
ResolvConfPath string
|
2015-11-12 14:55:17 -05:00
|
|
|
// Fields below here are platform specific.
|
|
|
|
}
|
|
|
|
|
2016-03-18 14:53:27 -04:00
|
|
|
// ExitStatus provides exit reasons for a container.
|
|
|
|
type ExitStatus struct {
|
|
|
|
// The exit code with which the container exited.
|
|
|
|
ExitCode int
|
|
|
|
}
|
|
|
|
|
2015-11-12 14:55:17 -05:00
|
|
|
// CreateDaemonEnvironment creates a new environment variable slice for this container.
|
2016-09-28 18:21:33 -04:00
|
|
|
func (container *Container) CreateDaemonEnvironment(_ bool, linkedEnv []string) []string {
|
2016-05-04 14:06:54 -04:00
|
|
|
// because the env on the container can override certain default values
|
|
|
|
// we need to replace the 'env' keys where they match and append anything
|
|
|
|
// else.
|
|
|
|
return utils.ReplaceOrAppendEnvValues(linkedEnv, container.Config.Env)
|
2015-11-12 14:55:17 -05:00
|
|
|
}
|
|
|
|
|
2016-09-04 03:17:58 -04:00
|
|
|
// UnmountIpcMounts unmounts Ipc related mounts.
|
2015-11-12 14:55:17 -05:00
|
|
|
// This is a NOOP on windows.
|
|
|
|
func (container *Container) UnmountIpcMounts(unmount func(pth string) error) {
|
|
|
|
}
|
|
|
|
|
|
|
|
// IpcMounts returns the list of Ipc related mounts.
|
2016-03-18 14:53:27 -04:00
|
|
|
func (container *Container) IpcMounts() []Mount {
|
2015-11-12 14:55:17 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-12-13 11:00:39 -05:00
|
|
|
// UnmountVolumes explicitly unmounts volumes from the container.
|
2015-12-21 19:45:31 -05:00
|
|
|
func (container *Container) UnmountVolumes(forceSyscall bool, volumeEventLog func(name, action string, attributes map[string]string)) error {
|
2016-09-22 21:20:39 -04:00
|
|
|
var (
|
|
|
|
volumeMounts []volume.MountPoint
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
|
|
|
for _, mntPoint := range container.MountPoints {
|
2016-09-30 12:40:15 -04:00
|
|
|
// Do not attempt to get the mountpoint destination on the host as it
|
|
|
|
// is not accessible on Windows in the case that a container is running.
|
|
|
|
// (It's a special reparse point which doesn't have any contextual meaning).
|
|
|
|
volumeMounts = append(volumeMounts, volume.MountPoint{Volume: mntPoint.Volume, ID: mntPoint.ID})
|
2016-09-22 21:20:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// atm, this is a no-op.
|
|
|
|
if volumeMounts, err = appendNetworkMounts(container, volumeMounts); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, volumeMount := range volumeMounts {
|
|
|
|
if volumeMount.Volume != nil {
|
|
|
|
if err := volumeMount.Volume.Unmount(volumeMount.ID); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
volumeMount.ID = ""
|
|
|
|
|
|
|
|
attributes := map[string]string{
|
|
|
|
"driver": volumeMount.Volume.DriverName(),
|
|
|
|
"container": container.ID,
|
|
|
|
}
|
|
|
|
volumeEventLog(volumeMount.Volume.Name(), "unmount", attributes)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-12 14:55:17 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// TmpfsMounts returns the list of tmpfs mounts
|
2016-03-18 14:53:27 -04:00
|
|
|
func (container *Container) TmpfsMounts() []Mount {
|
2016-06-06 05:57:11 -04:00
|
|
|
var mounts []Mount
|
|
|
|
return mounts
|
2015-11-12 14:55:17 -05:00
|
|
|
}
|
|
|
|
|
2016-01-04 10:58:20 -05:00
|
|
|
// UpdateContainer updates configuration of a container
|
2016-03-01 13:23:43 -05:00
|
|
|
func (container *Container) UpdateContainer(hostConfig *containertypes.HostConfig) error {
|
2016-01-04 10:58:20 -05:00
|
|
|
container.Lock()
|
|
|
|
defer container.Unlock()
|
|
|
|
resources := hostConfig.Resources
|
|
|
|
if resources.BlkioWeight != 0 || resources.CPUShares != 0 ||
|
|
|
|
resources.CPUPeriod != 0 || resources.CPUQuota != 0 ||
|
|
|
|
resources.CpusetCpus != "" || resources.CpusetMems != "" ||
|
|
|
|
resources.Memory != 0 || resources.MemorySwap != 0 ||
|
|
|
|
resources.MemoryReservation != 0 || resources.KernelMemory != 0 {
|
|
|
|
return fmt.Errorf("Resource updating isn't supported on Windows")
|
|
|
|
}
|
|
|
|
// update HostConfig of container
|
|
|
|
if hostConfig.RestartPolicy.Name != "" {
|
2016-08-15 04:38:47 -04:00
|
|
|
if container.HostConfig.AutoRemove && !hostConfig.RestartPolicy.IsNone() {
|
|
|
|
return fmt.Errorf("Restart policy cannot be updated because AutoRemove is enabled for the container")
|
|
|
|
}
|
2016-01-04 10:58:20 -05:00
|
|
|
container.HostConfig.RestartPolicy = hostConfig.RestartPolicy
|
|
|
|
}
|
2015-12-28 06:19:26 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-11-12 14:55:17 -05: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
|
|
|
|
}
|
2016-01-27 16:03:09 -05:00
|
|
|
|
|
|
|
// cleanResourcePath cleans a resource path by removing C:\ syntax, and prepares
|
|
|
|
// to combine with a volume path
|
|
|
|
func cleanResourcePath(path string) string {
|
|
|
|
if len(path) >= 2 {
|
|
|
|
c := path[0]
|
|
|
|
if path[1] == ':' && ('a' <= c && c <= 'z' || 'A' <= c && c <= 'Z') {
|
|
|
|
path = path[2:]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return filepath.Join(string(os.PathSeparator), path)
|
|
|
|
}
|
2016-03-01 13:23:43 -05:00
|
|
|
|
2016-03-09 23:33:21 -05:00
|
|
|
// BuildHostnameFile writes the container's hostname file.
|
|
|
|
func (container *Container) BuildHostnameFile() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-03-01 13:23:43 -05:00
|
|
|
// canMountFS determines if the file system for the container
|
|
|
|
// can be mounted locally. In the case of Windows, this is not possible
|
|
|
|
// for Hyper-V containers during WORKDIR execution for example.
|
|
|
|
func (container *Container) canMountFS() bool {
|
|
|
|
return !containertypes.Isolation.IsHyperV(container.HostConfig.Isolation)
|
|
|
|
}
|
2016-09-12 20:17:09 -04:00
|
|
|
|
|
|
|
// EnableServiceDiscoveryOnDefaultNetwork Enable service discovery on default network
|
|
|
|
func (container *Container) EnableServiceDiscoveryOnDefaultNetwork() bool {
|
|
|
|
return true
|
|
|
|
}
|