create_windows.go 2.9 KB

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