github.com/toplink-cn/moby@v0.0.0-20240305205811-460b4aebdf81/daemon/volumes_windows.go (about) 1 package daemon // import "github.com/docker/docker/daemon" 2 3 import ( 4 "context" 5 "sort" 6 7 "github.com/containerd/log" 8 "github.com/docker/docker/api/types/mount" 9 "github.com/docker/docker/container" 10 "github.com/docker/docker/internal/cleanups" 11 "github.com/docker/docker/internal/compatcontext" 12 "github.com/docker/docker/pkg/idtools" 13 volumemounts "github.com/docker/docker/volume/mounts" 14 ) 15 16 // setupMounts configures the mount points for a container by appending each 17 // of the configured mounts on the container to the OCI mount structure 18 // which will ultimately be passed into the oci runtime during container creation. 19 // It also ensures each of the mounts are lexicographically sorted. 20 // 21 // The cleanup function should be called as soon as the container has been 22 // started. 23 // 24 // BUGBUG TODO Windows containerd. This would be much better if it returned 25 // an array of runtime spec mounts, not container mounts. Then no need to 26 // do multiple transitions. 27 func (daemon *Daemon) setupMounts(ctx context.Context, c *container.Container) ([]container.Mount, func(context.Context) error, error) { 28 cleanups := cleanups.Composite{} 29 defer func() { 30 if err := cleanups.Call(compatcontext.WithoutCancel(ctx)); err != nil { 31 log.G(ctx).WithError(err).Warn("failed to cleanup temporary mounts created by MountPoint.Setup") 32 } 33 }() 34 35 var mnts []container.Mount 36 for _, mount := range c.MountPoints { // type is volumemounts.MountPoint 37 if err := daemon.lazyInitializeVolume(c.ID, mount); err != nil { 38 return nil, nil, err 39 } 40 s, c, err := mount.Setup(ctx, c.MountLabel, idtools.Identity{}, nil) 41 if err != nil { 42 return nil, nil, err 43 } 44 cleanups.Add(c) 45 46 mnts = append(mnts, container.Mount{ 47 Source: s, 48 Destination: mount.Destination, 49 Writable: mount.RW, 50 }) 51 } 52 53 sort.Sort(mounts(mnts)) 54 return mnts, cleanups.Release(), nil 55 } 56 57 // setBindModeIfNull is platform specific processing which is a no-op on 58 // Windows. 59 func setBindModeIfNull(bind *volumemounts.MountPoint) { 60 return 61 } 62 63 func (daemon *Daemon) validateBindDaemonRoot(m mount.Mount) (bool, error) { 64 return false, nil 65 }