create_windows.go 2.9 KB

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