docker/cli · error
cannot mix 'image-*' options with mount type
Error message
cannot mix 'image-*' options with mount type '%s'
What it means
Returned by validateExclusiveOptions (opts/mount_utils.go:59) when a mount's Type is not TypeImage but ImageOptions is non-nil. The image-* options (image-subpath) are only valid for type=image mounts.
Solutions
- Use type=image when you need image-subpath.
- Or remove image-subpath from bind/volume/tmpfs/cluster mounts.
Example fix
// before --mount "type=bind,source=/h,target=/d,image-subpath=app/bin" // after --mount "type=image,source=myimg,target=/d,image-subpath=app/bin"
Defensive patterns
Strategy: validation
Validate before calling
func validateExclusive(m mount.Mount) error {
if m.Type != mount.TypeImage && m.ImageOptions != nil {
return fmt.Errorf("image-* options require type=image, got %s", m.Type)
}
return nil
} Try / catch
if err := m.Set(spec); err != nil {
return fmt.Errorf("mount %q: %w", spec, err)
} Prevention
- Only set ImageOptions on type=image mounts.
- Isolate image-mount construction in its own builder function.
- Test that image-subpath implies type=image.
When it happens
Trigger: Setting image-subpath on a non-image mount, e.g. `--mount type=volume,source=v,target=/d,image-subpath=foo`, or programmatically setting mount.ImageOptions on a Mount whose Type isn't TypeImage.
Common situations: Mixing image-mount options into a bind/volume spec, or a templating tool emitting image-subpath unconditionally.
Related errors
- cannot mix 'bind-*' options with mount type
- cannot mix 'volume-*' options with mount type
- cannot mix 'tmpfs-*' options with mount type
- cannot mix 'cluster-*' options with mount type
- invalid image reference for service
AI-assisted analysis of docker/cli@4f84911bfe (2026-08-07).
Data as JSON: /api/errors/92b6be8505909aa0.
Report an issue: GitHub.
Appendix: source
Thrown at opts/mount_utils.go:59
// 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.
func parseBoolValue(key string, val string, hasValue bool) (bool, error) {
if !hasValue {
return true, nilView on GitHub (pinned to 4f84911bfe)