{"record":{"id":"b905e52bdc25d0f7","repo":"docker/compose","slug":"invalid-scale-specifier-can-t-parse-replica-value","errorCode":null,"errorMessage":"invalid scale specifier: can't parse replica value as int: %v","messagePattern":"invalid scale specifier: can't parse replica value as int: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/compose/scale.go","lineNumber":123,"sourceCode":"\tservice, err := project.GetService(name)\n\tif err != nil {\n\t\treturn err\n\t}\n\tservice.SetScale(replicas)\n\tproject.Services[name] = service\n\treturn nil\n}\n\nfunc parseServicesReplicasArgs(args []string) (map[string]int, error) {\n\tserviceReplicaTuples := map[string]int{}\n\tfor _, arg := range args {\n\t\tkey, val, ok := strings.Cut(arg, \"=\")\n\t\tif !ok || key == \"\" || val == \"\" {\n\t\t\treturn nil, fmt.Errorf(\"invalid scale specifier: %s\", arg)\n\t\t}\n\t\tintValue, err := strconv.Atoi(val)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"invalid scale specifier: can't parse replica value as int: %v\", arg)\n\t\t}\n\t\tserviceReplicaTuples[key] = intValue\n\t}\n\treturn serviceReplicaTuples, nil\n}\n","sourceCodeStart":105,"sourceCodeEnd":129,"githubUrl":"https://github.com/docker/compose/blob/ddc4b044b62e9f715212ea4143fa830fac76382f/cmd/compose/scale.go#L105-L129","documentation":"Thrown by parseServicesReplicasArgs in `docker compose scale` when the SERVICE=REPLICAS argument is well-formed but the replica value fails strconv.Atoi. The message helpfully embeds the whole offending arg, so the exact token that failed to parse is visible. Only plain base-10 integers are accepted (an optional sign followed by digits); floats, scientific notation, or suffixes like '2x' are rejected.","triggerScenarios":"Running `docker compose scale web=2.0`, `web=1e3`, `web=three`, or a value with whitespace like `web= 2` (leading space after '='). Also `scale web=08x` or values containing unit suffixes. Any single failure aborts the entire scale command before the project is loaded.","commonSituations":"Scripts computing a replica count and passing a float (e.g. output of a division like `4/2` in bc, or a Terraform/Ansible variable typed as float); passing a percentage or a human-written count like '~2'; whitespace introduced by variable expansion `scale web=${COUNT}` where COUNT=' 2'.","solutions":["Use a plain integer: `docker compose scale web=3`.","If the count comes from a script, round/convert it to an integer first (e.g. `printf '%.0f'`, `${COUNT//[[:space:]]/}`).","Verify the exact token in the error message — it shows the full arg including the value that failed Atoi."],"exampleFix":"# before\ndocker compose scale web=$REPLICAS   # REPLICAS=2.0\n\n# after\nREPLICAS=$(printf '%.0f' \"$REPLICAS\")\ndocker compose scale web=$REPLICAS","handlingStrategy":"validation","validationCode":"if ! [[ \"$VAL\" =~ ^-?[0-9]+$ ]]; then echo \"replicas must be an integer: $VAL\" >&2; exit 2; fi\ndocker compose scale \"web=$VAL\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Round floats before passing: printf '%.0f'.","Strip whitespace from computed counts.","Validate with a regex ^-?[0-9]+$ in wrappers."],"tags":["cli","scale","argument-parsing","strconv","compose"],"backgroundTag":null,"analyzedSha":"ddc4b044b62e9f715212ea4143fa830fac76382f","analyzedAt":"2026-08-15T13:31:42.319Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}