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