{"record":{"id":"b0318977c1020226","repo":"docker/cli","slug":"gpu-request-key-s-can-be-specified-only-once","errorCode":null,"errorMessage":"gpu request key '%s' can be specified only once","messagePattern":"gpu request key '(.+?)' can be specified only once","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"opts/gpus.go","lineNumber":50,"sourceCode":"\n// Set a new mount value\n//\n//nolint:gocyclo\nfunc (o *GpuOpts) Set(value string) error {\n\tcsvReader := csv.NewReader(strings.NewReader(value))\n\tfields, err := csvReader.Read()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\treq := container.DeviceRequest{}\n\n\tseen := map[string]struct{}{}\n\t// Set writable as the default\n\tfor _, field := range fields {\n\t\tkey, val, withValue := strings.Cut(field, \"=\")\n\t\tif _, ok := seen[key]; ok {\n\t\t\treturn fmt.Errorf(\"gpu request key '%s' can be specified only once\", key)\n\t\t}\n\t\tseen[key] = struct{}{}\n\n\t\tif !withValue {\n\t\t\tseen[\"count\"] = struct{}{}\n\t\t\treq.Count, err = parseCount(key)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\n\t\tswitch key {\n\t\tcase \"driver\":\n\t\t\treq.Driver = val\n\t\tcase \"count\":\n\t\t\treq.Count, err = parseCount(val)\n\t\t\tif err != nil {","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/opts/gpus.go#L32-L68","documentation":"GpuOpts.Set tracks each key it has seen and rejects a second occurrence of the same key. This includes a bare integer (which implicitly counts as a \"count\" key), so two bare integers or count= twice will both trigger it. Each key may appear once per request.","triggerScenarios":"--gpus with a duplicate key, e.g. --gpus 'count=1,count=2', --gpus '1,2' (two bare counts), or --gpus 'driver=nvidia,driver=amd'.","commonSituations":"Combining the shorthand count and the count= key; copy-paste producing a doubled field; trying to express two GPU groups inside one --gpus argument.","solutions":["Remove the duplicate key so each appears once.","For multiple separate device requests, pass multiple --gpus flags rather than packing them into one.","Use the explicit key form (count=, driver=, device=) to avoid ambiguity with bare integers.","Validate/dedupe keys before calling Set if constructing the value programmatically."],"exampleFix":"# before\ndocker run --gpus 'count=1,count=2' myimg\n\n# after (two separate requests)\ndocker run --gpus count=1 --gpus count=2 myimg","handlingStrategy":"validation","validationCode":"// Dedupe keys before constructing the --gpus value.\nfunc dedupeKeys(fields []string) error {\n    seen := map[string]struct{}{}\n    for _, f := range fields {\n        key, _, _ := strings.Cut(f, \"=\")\n        if _, isCount := seen[key]; isCount {\n            return fmt.Errorf(\"duplicate key %q\", key)\n        }\n        seen[key] = struct{}{}\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Specify each key at most once per --gpus argument.","Use multiple --gpus flags for separate device requests.","Prefer the explicit count= form to avoid bare-integer collisions."],"tags":["docker","gpu","parsing","validation"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}