create_windows.go 3.1 KB

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