{"record":{"id":"cf5b31bee5c47736","repo":"docker/cli","slug":"conflicting-options-cannot-specify-a-volume-name","errorCode":null,"errorMessage":"conflicting options: cannot specify a volume-name through both --name and as a positional arg","messagePattern":"conflicting options: cannot specify a volume-name through both --name and as a positional arg","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/volume/create.go","lineNumber":58,"sourceCode":"}\n\nfunc newCreateCommand(dockerCLI command.Cli) *cobra.Command {\n\toptions := createOptions{\n\t\tdriverOpts:        *opts.NewMapOpts(nil, nil),\n\t\tlabels:            opts.NewListOpts(opts.ValidateLabel),\n\t\tsecrets:           *opts.NewMapOpts(nil, nil),\n\t\trequisiteTopology: opts.NewListOpts(nil),\n\t\tpreferredTopology: opts.NewListOpts(nil),\n\t}\n\n\tcmd := &cobra.Command{\n\t\tUse:   \"create [OPTIONS] [VOLUME]\",\n\t\tShort: \"Create a volume\",\n\t\tArgs:  cli.RequiresMaxArgs(1),\n\t\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\t\tif len(args) == 1 {\n\t\t\t\tif options.name != \"\" {\n\t\t\t\t\treturn errors.New(\"conflicting options: cannot specify a volume-name through both --name and as a positional arg\")\n\t\t\t\t}\n\t\t\t\toptions.name = args[0]\n\t\t\t}\n\t\t\toptions.cluster = hasClusterVolumeOptionSet(cmd.Flags())\n\t\t\treturn runCreate(cmd.Context(), dockerCLI, options)\n\t\t},\n\t\tValidArgsFunction:     cobra.NoFileCompletions,\n\t\tDisableFlagsInUseLine: true,\n\t}\n\tflags := cmd.Flags()\n\tflags.StringVarP(&options.driver, \"driver\", \"d\", \"local\", \"Specify volume driver name\")\n\tflags.StringVar(&options.name, \"name\", \"\", \"Specify volume name\")\n\tflags.Lookup(\"name\").Hidden = true\n\tflags.VarP(&options.driverOpts, \"opt\", \"o\", \"Set driver specific options\")\n\tflags.Var(&options.labels, \"label\", \"Set metadata for a volume\")\n\n\t// flags for cluster volumes only\n\tflags.StringVar(&options.group, \"group\", \"\", \"Cluster Volume group (cluster volumes)\")","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/volume/create.go#L40-L76","documentation":"Returned by 'docker volume create' when the volume name is supplied both via the hidden --name flag AND as a positional argument. The command accepts at most one positional arg (VOLUME), and at create.go:57-59 it checks: if a positional arg was given and options.name is already non-empty, the two sources conflict and the command aborts. Only one way of naming the volume is allowed.","triggerScenarios":"Running 'docker volume create --name myvol myvol2' (both --name and a trailing positional). The --name flag is hidden (create.go:71), so this typically arises from scripts or completion tools that set --name and also append the name positionally.","commonSituations":"Wrapper scripts/Makefiles that build the create command by concatenating '--name $N' and '$N'. Shell aliases or completion helpers that inject --name. Migrating from an older tool that emitted --name where the modern CLI expects a positional.","solutions":["Drop the --name flag and pass the volume name only as the trailing positional: 'docker volume create myvol'.","If you must keep --name, ensure no positional volume argument follows it.","Audit the script/alias that assembles the command for accidental double-specification of the name."],"exampleFix":"# before\ndocker volume create --name mydata mydata\n\n# after\ndocker volume create mydata","handlingStrategy":"validation","validationCode":"// Build a 'docker volume create' arg list ensuring name is set exactly once.\nfunc buildVolumeCreateArgs(name string, opts []string) []string {\n    args := []string{\"volume\", \"create\"}\n    // Do NOT also append name positionally if you set --name; choose one form.\n    args = append(args, \"--name\", name)\n    args = append(args, opts...)\n    return args // never append name again as positional\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Standardize on the positional form ('docker volume create <name>') in all scripts; avoid the hidden --name.","Unit-test wrapper scripts that assemble create commands to assert the name appears once.","Run 'docker volume create --help' to confirm which flags your CLI version exposes."],"tags":["docker-volume","cli","argument-conflict","validation"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}