github.com/kunnos/engine@v1.13.1/daemon/create_windows.go (about)

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