github.com/olljanat/moby@v1.13.1/daemon/cluster/executor/container/validate.go (about) 1 package container 2 3 import ( 4 "fmt" 5 "path/filepath" 6 7 "github.com/docker/swarmkit/api" 8 ) 9 10 func validateMounts(mounts []api.Mount) error { 11 for _, mount := range mounts { 12 // Target must always be absolute 13 if !filepath.IsAbs(mount.Target) { 14 return fmt.Errorf("invalid mount target, must be an absolute path: %s", mount.Target) 15 } 16 17 switch mount.Type { 18 // The checks on abs paths are required due to the container API confusing 19 // volume mounts as bind mounts when the source is absolute (and vice-versa) 20 // See #25253 21 // TODO: This is probably not necessary once #22373 is merged 22 case api.MountTypeBind: 23 if !filepath.IsAbs(mount.Source) { 24 return fmt.Errorf("invalid bind mount source, must be an absolute path: %s", mount.Source) 25 } 26 case api.MountTypeVolume: 27 if filepath.IsAbs(mount.Source) { 28 return fmt.Errorf("invalid volume mount source, must not be an absolute path: %s", mount.Source) 29 } 30 case api.MountTypeTmpfs: 31 if mount.Source != "" { 32 return fmt.Errorf("invalid tmpfs source, source must be empty") 33 } 34 default: 35 return fmt.Errorf("invalid mount type: %s", mount.Type) 36 } 37 } 38 return nil 39 }