github.com/ssdev-go/moby@v17.12.1-ce-rc2+incompatible/daemon/create_windows.go (about)

     1  package daemon
     2  
     3  import (
     4  	"fmt"
     5  	"runtime"
     6  
     7  	containertypes "github.com/docker/docker/api/types/container"
     8  	"github.com/docker/docker/container"
     9  	"github.com/docker/docker/pkg/stringid"
    10  	"github.com/docker/docker/volume"
    11  )
    12  
    13  // createContainerOSSpecificSettings performs host-OS specific container create functionality
    14  func (daemon *Daemon) createContainerOSSpecificSettings(container *container.Container, config *containertypes.Config, hostConfig *containertypes.HostConfig) error {
    15  
    16  	if container.OS == runtime.GOOS {
    17  		// Make sure the host config has the default daemon isolation if not specified by caller.
    18  		if containertypes.Isolation.IsDefault(containertypes.Isolation(hostConfig.Isolation)) {
    19  			hostConfig.Isolation = daemon.defaultIsolation
    20  		}
    21  	} else {
    22  		// LCOW must be a Hyper-V container as you can't run a shared kernel when one
    23  		// is a Windows kernel, the other is a Linux kernel.
    24  		if containertypes.Isolation.IsProcess(containertypes.Isolation(hostConfig.Isolation)) {
    25  			return fmt.Errorf("process isolation is invalid for Linux containers on Windows")
    26  		}
    27  		hostConfig.Isolation = "hyperv"
    28  	}
    29  	parser := volume.NewParser(container.OS)
    30  	for spec := range config.Volumes {
    31  
    32  		mp, err := parser.ParseMountRaw(spec, hostConfig.VolumeDriver)
    33  		if err != nil {
    34  			return fmt.Errorf("Unrecognised volume spec: %v", err)
    35  		}
    36  
    37  		// If the mountpoint doesn't have a name, generate one.
    38  		if len(mp.Name) == 0 {
    39  			mp.Name = stringid.GenerateNonCryptoID()
    40  		}
    41  
    42  		// Skip volumes for which we already have something mounted on that
    43  		// destination because of a --volume-from.
    44  		if container.IsDestinationMounted(mp.Destination) {
    45  			continue
    46  		}
    47  
    48  		volumeDriver := hostConfig.VolumeDriver
    49  
    50  		// Create the volume in the volume driver. If it doesn't exist,
    51  		// a new one will be created.
    52  		v, err := daemon.volumes.CreateWithRef(mp.Name, volumeDriver, container.ID, nil, nil)
    53  		if err != nil {
    54  			return err
    55  		}
    56  
    57  		// FIXME Windows: This code block is present in the Linux version and
    58  		// allows the contents to be copied to the container FS prior to it
    59  		// being started. However, the function utilizes the FollowSymLinkInScope
    60  		// path which does not cope with Windows volume-style file paths. There
    61  		// is a separate effort to resolve this (@swernli), so this processing
    62  		// is deferred for now. A case where this would be useful is when
    63  		// a dockerfile includes a VOLUME statement, but something is created
    64  		// in that directory during the dockerfile processing. What this means
    65  		// on Windows for TP5 is that in that scenario, the contents will not
    66  		// copied, but that's (somewhat) OK as HCS will bomb out soon after
    67  		// at it doesn't support mapped directories which have contents in the
    68  		// destination path anyway.
    69  		//
    70  		// Example for repro later:
    71  		//   FROM windowsservercore
    72  		//   RUN mkdir c:\myvol
    73  		//   RUN copy c:\windows\system32\ntdll.dll c:\myvol
    74  		//   VOLUME "c:\myvol"
    75  		//
    76  		// Then
    77  		//   docker build -t vol .
    78  		//   docker run -it --rm vol cmd  <-- This is where HCS will error out.
    79  		//
    80  		//	// never attempt to copy existing content in a container FS to a shared volume
    81  		//	if v.DriverName() == volume.DefaultDriverName {
    82  		//		if err := container.CopyImagePathContent(v, mp.Destination); err != nil {
    83  		//			return err
    84  		//		}
    85  		//	}
    86  
    87  		// Add it to container.MountPoints
    88  		container.AddMountPointWithVolume(mp.Destination, v, mp.RW)
    89  	}
    90  	return nil
    91  }