docker/cli · error

cannot mix 'volume-*' options with mount type

Error message

cannot mix 'volume-*' options with mount type '%s'

What it means

Returned by validateExclusiveOptions (opts/mount_utils.go:56) when a mount's Type is not TypeVolume but VolumeOptions is non-nil. Volume-specific options (volume-nocopy, volume-label, volume-driver, volume-opt, volume-subpath) are only permitted with type=volume.

Solutions

  1. Use type=volume if you need volume-* options.
  2. Or strip all volume-* options when mounting as bind/tmpfs/image/cluster.

Example fix

// before
--mount "type=bind,source=/h,target=/d,volume-driver=local"

// after
--mount "type=volume,source=v,target=/d,volume-driver=local"
Defensive patterns

Strategy: validation

Validate before calling

func validateExclusive(m mount.Mount) error {
    if m.Type != mount.TypeVolume && m.VolumeOptions != nil {
        return fmt.Errorf("volume-* options require type=volume, got %s", m.Type)
    }
    return nil
}

Try / catch

if err := m.Set(spec); err != nil {
    return fmt.Errorf("mount %q: %w", spec, err)
}

Prevention

When it happens

Trigger: Setting any volume-* option on a type=bind/tmpfs/image/cluster mount, e.g. `--mount type=bind,source=/h,target=/d,volume-nocopy`, or programmatically setting mount.VolumeOptions on a non-volume Mount.

Common situations: Copy-pasting a volume mount spec and changing only the type, or a generator that always emits volume-driver.

Related errors


AI-assisted analysis of docker/cli@4f84911bfe (2026-08-07). Data as JSON: /api/errors/afc37b9e0e2ed14f. Report an issue: GitHub.

Appendix: source

Thrown at opts/mount_utils.go:56

}

// validateExclusiveOptions checks if the given mount config only contains
// options for the given mount-type.
//
// This is the client-side equivalent of [mounts.validateExclusiveOptions] in
// the daemon, but with error-messages matching client-side flags / options.
//
// [mounts.validateExclusiveOptions]: https://github.com/moby/moby/blob/v2.0.0-beta.6/daemon/volume/mounts/validate.go#L31-L50
func validateExclusiveOptions(m *mount.Mount) error {
	if m.Type == "" {
		return errors.New("type is required")
	}

	if m.Type != mount.TypeBind && m.BindOptions != nil {
		return fmt.Errorf("cannot mix 'bind-*' options with mount type '%s'", m.Type)
	}
	if m.Type != mount.TypeVolume && m.VolumeOptions != nil {
		return fmt.Errorf("cannot mix 'volume-*' options with mount type '%s'", m.Type)
	}
	if m.Type != mount.TypeImage && m.ImageOptions != nil {
		return fmt.Errorf("cannot mix 'image-*' options with mount type '%s'", m.Type)
	}
	if m.Type != mount.TypeTmpfs && m.TmpfsOptions != nil {
		return fmt.Errorf("cannot mix 'tmpfs-*' options with mount type '%s'", m.Type)
	}
	if m.Type != mount.TypeCluster && m.ClusterOptions != nil {
		return fmt.Errorf("cannot mix 'cluster-*' options with mount type '%s'", m.Type)
	}
	return nil
}

// parseBoolValue returns the boolean value represented by the string. It returns
// true if no value is set.
//
// It is similar to [strconv.ParseBool], but only accepts 1, true, 0, false.
// Any other value returns an error.

View on GitHub (pinned to 4f84911bfe)