github.com/moby/docker@v26.1.3+incompatible/volume/mounts/parser.go (about)

     1  package mounts // import "github.com/docker/docker/volume/mounts"
     2  
     3  import (
     4  	"errors"
     5  	"runtime"
     6  
     7  	"github.com/docker/docker/api/types/mount"
     8  )
     9  
    10  // ErrVolumeTargetIsRoot is returned when the target destination is root.
    11  // It's used by both LCOW and Linux parsers.
    12  var ErrVolumeTargetIsRoot = errors.New("invalid specification: destination can't be '/'")
    13  
    14  // errAnonymousVolumeWithSubpath is returned when Subpath is specified for
    15  // anonymous volume.
    16  var errAnonymousVolumeWithSubpath = errors.New("must not set Subpath when using anonymous volumes")
    17  
    18  // errInvalidSubpath is returned when the provided Subpath is not lexically an
    19  // relative path within volume.
    20  var errInvalidSubpath = errors.New("subpath must be a relative path within the volume")
    21  
    22  // read-write modes
    23  var rwModes = map[string]bool{
    24  	"rw": true,
    25  	"ro": true, // attempts recursive read-only if possible
    26  }
    27  
    28  // Parser represents a platform specific parser for mount expressions
    29  type Parser interface {
    30  	ParseMountRaw(raw, volumeDriver string) (*MountPoint, error)
    31  	ParseMountSpec(cfg mount.Mount) (*MountPoint, error)
    32  	ParseVolumesFrom(spec string) (string, string, error)
    33  	DefaultPropagationMode() mount.Propagation
    34  	ConvertTmpfsOptions(opt *mount.TmpfsOptions, readOnly bool) (string, error)
    35  	DefaultCopyMode() bool
    36  	ValidateVolumeName(name string) error
    37  	ReadWrite(mode string) bool
    38  	IsBackwardCompatible(m *MountPoint) bool
    39  	HasResource(m *MountPoint, absPath string) bool
    40  	ValidateTmpfsMountDestination(dest string) error
    41  	ValidateMountConfig(mt *mount.Mount) error
    42  }
    43  
    44  // NewParser creates a parser for the current host OS
    45  func NewParser() Parser {
    46  	if runtime.GOOS == "windows" {
    47  		return NewWindowsParser()
    48  	}
    49  	return NewLinuxParser()
    50  }