create_windows.go 3.3 KB

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