{"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/e9452d6e785f6e365712b9d71bd7517591773c86/cli/command/volume/create.go#L40-L76","documentation":"Raised by `docker volume create` when a volume name is supplied both as the positional argument and via the --name flag. Since both set the same field, the CLI refuses the ambiguous invocation rather than silently picking one.","triggerScenarios":"`docker volume create --name foo bar` — cobra RunE sees len(args)==1 and options.name != \"\" at cli/command/volume/create.go:58.","commonSituations":"Scripts migrated from very old Docker versions where --name was the documented way, later edited to also pass a positional name; wrapper tooling that appends a positional arg while users also set --name.","solutions":["Pass the name only once, preferably positionally: `docker volume create foo`.","Remove the deprecated-style --name flag from scripts, or drop the positional arg if you keep --name."],"exampleFix":"# before\ndocker volume create --name mydata mydata\n# after\ndocker volume create mydata","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["docker-cli","volume","flag-conflict","validation"],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}