{"record":{"id":"b03c02ee2994a133","repo":"docker/cli","slug":"type-is-required","errorCode":null,"errorMessage":"type is required","messagePattern":"type is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"opts/mount_utils.go","lineNumber":49,"sourceCode":"\t\t\t\t//\t# no error\n\t\t\t\treturn errors.New(\"option 'bind-recursive=readonly' requires 'bind-propagation=rprivate' to be specified in conjunction\")\n\t\t\t}\n\t\t}\n\t}\n\n\treturn nil\n}\n\n// validateExclusiveOptions checks if the given mount config only contains\n// options for the given mount-type.\n//\n// This is the client-side equivalent of [mounts.validateExclusiveOptions] in\n// the daemon, but with error-messages matching client-side flags / options.\n//\n// [mounts.validateExclusiveOptions]: https://github.com/moby/moby/blob/v2.0.0-beta.6/daemon/volume/mounts/validate.go#L31-L50\nfunc validateExclusiveOptions(m *mount.Mount) error {\n\tif m.Type == \"\" {\n\t\treturn errors.New(\"type is required\")\n\t}\n\n\tif m.Type != mount.TypeBind && m.BindOptions != nil {\n\t\treturn fmt.Errorf(\"cannot mix 'bind-*' options with mount type '%s'\", m.Type)\n\t}\n\tif m.Type != mount.TypeVolume && m.VolumeOptions != nil {\n\t\treturn fmt.Errorf(\"cannot mix 'volume-*' options with mount type '%s'\", m.Type)\n\t}\n\tif m.Type != mount.TypeImage && m.ImageOptions != nil {\n\t\treturn fmt.Errorf(\"cannot mix 'image-*' options with mount type '%s'\", m.Type)\n\t}\n\tif m.Type != mount.TypeTmpfs && m.TmpfsOptions != nil {\n\t\treturn fmt.Errorf(\"cannot mix 'tmpfs-*' options with mount type '%s'\", m.Type)\n\t}\n\tif m.Type != mount.TypeCluster && m.ClusterOptions != nil {\n\t\treturn fmt.Errorf(\"cannot mix 'cluster-*' options with mount type '%s'\", m.Type)\n\t}\n\treturn nil","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/opts/mount_utils.go#L31-L67","documentation":"Returned by validateExclusiveOptions (opts/mount_utils.go:49) when the mount's Type field is an empty string. When using the CLI's MountOpt.Set parser, Type defaults to mounttypes.TypeVolume, so this error only triggers when a mount.Mount struct is constructed directly (e.g., via the Go SDK/API client) without explicitly setting the Type field.","triggerScenarios":"validateMountOptions is called on a mount.Mount struct where m.Type is \"\" (empty string). This occurs in programmatic/SDK usage where a mount is built without setting Type, not through the CLI --mount flag parser which always defaults Type to TypeVolume.","commonSituations":"Go code using the Docker client SDK to create a container with a HostConfig.Mounts entry that omits the Type field, or deserialized mount JSON lacking a type field.","solutions":["Set the Type field on the mount.Mount struct to one of: mount.TypeBind, mount.TypeVolume, mount.TypeTmpfs, mount.TypeImage, mount.TypeCluster.","If building mounts from user input, default Type to mount.TypeVolume like the CLI parser does."],"exampleFix":"// before: no type specified\nmount := mount.Mount{\n    Source: \"/data\",\n    Target: \"/data\",\n}\n\n// after: set type explicitly\nmount := mount.Mount{\n    Type:   mount.TypeBind,\n    Source: \"/data\",\n    Target: \"/data\",\n}","handlingStrategy":"validation","validationCode":"func validateMountType(m mounttypes.Mount) error {\n    if m.Type == \"\" {\n        return fmt.Errorf(\"mount type is required (one of: bind, volume, tmpfs, image, cluster)\")\n    }\n    return nil\n}\n\n// Or default to volume like the CLI parser does:\nfunc ensureMountType(m *mounttypes.Mount) {\n    if m.Type == \"\" {\n        m.Type = mounttypes.TypeVolume\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := validateMountOptions(&m); err != nil {\n    if err.Error() == \"type is required\" {\n        m.Type = mounttypes.TypeVolume // or TypeBind\n        return validateMountOptions(&m)\n    }\n    return err\n}","preventionTips":["Always set the Type field when constructing mount.Mount structs programmatically.","Default Type to mount.TypeVolume if building mounts from user input, matching the CLI parser behavior.","Validate mount structs before passing them to the Docker client API."],"tags":["mount","validation","api","sdk"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}