github.com/docker/docker@v299999999.0.0-20200612211812-aaf470eca7b5+incompatible/daemon/cluster/executor/container/validate.go (about)

     1  package container // import "github.com/docker/docker/daemon/cluster/executor/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  		// except if target is Windows named pipe
    15  		if !filepath.IsAbs(mount.Target) && mount.Type != api.MountTypeNamedPipe {
    16  			return fmt.Errorf("invalid mount target, must be an absolute path: %s", mount.Target)
    17  		}
    18  
    19  		switch mount.Type {
    20  		// The checks on abs paths are required due to the container API confusing
    21  		// volume mounts as bind mounts when the source is absolute (and vice-versa)
    22  		// See #25253
    23  		// TODO: This is probably not necessary once #22373 is merged
    24  		case api.MountTypeBind:
    25  			if !filepath.IsAbs(mount.Source) {
    26  				return fmt.Errorf("invalid bind mount source, must be an absolute path: %s", mount.Source)
    27  			}
    28  		case api.MountTypeVolume:
    29  			if filepath.IsAbs(mount.Source) {
    30  				return fmt.Errorf("invalid volume mount source, must not be an absolute path: %s", mount.Source)
    31  			}
    32  		case api.MountTypeTmpfs:
    33  			if mount.Source != "" {
    34  				return errors.New("invalid tmpfs source, source must be empty")
    35  			}
    36  		case api.MountTypeNamedPipe:
    37  			if mount.Source == "" {
    38  				return errors.New("invalid npipe source, source must not be empty")
    39  			}
    40  		default:
    41  			return fmt.Errorf("invalid mount type: %s", mount.Type)
    42  		}
    43  	}
    44  	return nil
    45  }