diff --git a/volume/lcow_parser.go b/volume/lcow_parser.go index 8d15f0d9d7..b6a49d84df 100644 --- a/volume/lcow_parser.go +++ b/volume/lcow_parser.go @@ -2,7 +2,6 @@ package volume import ( "errors" - "fmt" "path" "github.com/docker/docker/api/types/mount" @@ -10,7 +9,7 @@ import ( var lcowSpecificValidators mountValidator = func(m *mount.Mount) error { if path.Clean(m.Target) == "/" { - return fmt.Errorf("invalid specification: destination can't be '/'") + return ErrVolumeTargetIsRoot } if m.Type == mount.TypeNamedPipe { return errors.New("Linux containers on Windows do not support named pipe mounts") diff --git a/volume/linux_parser.go b/volume/linux_parser.go index fd54e82162..43f1915382 100644 --- a/volume/linux_parser.go +++ b/volume/linux_parser.go @@ -29,7 +29,7 @@ func linuxSplitRawSpec(raw string) ([]string, error) { func linuxValidateNotRoot(p string) error { p = path.Clean(strings.Replace(p, `\`, `/`, -1)) if p == "/" { - return fmt.Errorf("invalid specification: destination can't be '/'") + return ErrVolumeTargetIsRoot } return nil } diff --git a/volume/parser.go b/volume/parser.go index 13fd7d1489..0b720313c7 100644 --- a/volume/parser.go +++ b/volume/parser.go @@ -1,6 +1,7 @@ package volume import ( + "errors" "runtime" "github.com/docker/docker/api/types/mount" @@ -13,6 +14,10 @@ const ( OSWindows = "windows" ) +// ErrVolumeTargetIsRoot is returned when the target destination is root. +// It's used by both LCOW and Linux parsers. +var ErrVolumeTargetIsRoot = errors.New("invalid specification: destination can't be '/'") + // Parser represents a platform specific parser for mount expressions type Parser interface { ParseMountRaw(raw, volumeDriver string) (*MountPoint, error)