github.com/vincentwoo/docker@v0.7.3-0.20160116130405-82401a4b13c0/daemon/create_windows.go (about)

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