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