gopkg.in/docker/docker.v23@v23.0.11/daemon/create_windows.go (about)

     1  package daemon // import "github.com/docker/docker/daemon"
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	containertypes "github.com/docker/docker/api/types/container"
     8  	"github.com/docker/docker/container"
     9  	volumemounts "github.com/docker/docker/volume/mounts"
    10  	volumeopts "github.com/docker/docker/volume/service/opts"
    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  	if containertypes.Isolation.IsDefault(hostConfig.Isolation) {
    16  		// Make sure the host config has the default daemon isolation if not specified by caller.
    17  		hostConfig.Isolation = daemon.defaultIsolation
    18  	}
    19  	parser := volumemounts.NewParser()
    20  	for spec := range config.Volumes {
    21  
    22  		mp, err := parser.ParseMountRaw(spec, hostConfig.VolumeDriver)
    23  		if err != nil {
    24  			return fmt.Errorf("Unrecognised volume spec: %v", err)
    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  
    35  		// Create the volume in the volume driver. If it doesn't exist,
    36  		// a new one will be created.
    37  		v, err := daemon.volumes.Create(context.TODO(), "", volumeDriver, volumeopts.WithCreateReference(container.ID))
    38  		if err != nil {
    39  			return err
    40  		}
    41  
    42  		// FIXME Windows: This code block is present in the Linux version and
    43  		// allows the contents to be copied to the container FS prior to it
    44  		// being started. However, the function utilizes the FollowSymLinkInScope
    45  		// path which does not cope with Windows volume-style file paths. There
    46  		// is a separate effort to resolve this (@swernli), so this processing
    47  		// is deferred for now. A case where this would be useful is when
    48  		// a dockerfile includes a VOLUME statement, but something is created
    49  		// in that directory during the dockerfile processing. What this means
    50  		// on Windows for TP5 is that in that scenario, the contents will not
    51  		// copied, but that's (somewhat) OK as HCS will bomb out soon after
    52  		// at it doesn't support mapped directories which have contents in the
    53  		// destination path anyway.
    54  		//
    55  		// Example for repro later:
    56  		//   FROM windowsservercore
    57  		//   RUN mkdir c:\myvol
    58  		//   RUN copy c:\windows\system32\ntdll.dll c:\myvol
    59  		//   VOLUME "c:\myvol"
    60  		//
    61  		// Then
    62  		//   docker build -t vol .
    63  		//   docker run -it --rm vol cmd  <-- This is where HCS will error out.
    64  		//
    65  		//	// never attempt to copy existing content in a container FS to a shared volume
    66  		//	if v.DriverName() == volume.DefaultDriverName {
    67  		//		if err := container.CopyImagePathContent(v, mp.Destination); err != nil {
    68  		//			return err
    69  		//		}
    70  		//	}
    71  
    72  		// Add it to container.MountPoints
    73  		container.AddMountPointWithVolume(mp.Destination, &volumeWrapper{v: v, s: daemon.volumes}, mp.RW)
    74  	}
    75  	return nil
    76  }