{"id":"b51de2da9f218a47","repo":"docker/cli","slug":"scale-can-only-be-used-with-replicated-or-replicat","errorCode":null,"errorMessage":"scale can only be used with replicated or replicated-job mode","messagePattern":"scale can only be used with replicated or replicated-job mode","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/service/scale.go","lineNumber":108,"sourceCode":"\t\t}\n\t}\n\treturn errors.Join(errs...)\n}\n\nfunc runServiceScale(ctx context.Context, apiClient client.ServiceAPIClient, serviceID string, scale uint64) (warnings []string, _ error) {\n\tres, err := apiClient.ServiceInspect(ctx, serviceID, client.ServiceInspectOptions{})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tserviceMode := &res.Service.Spec.Mode\n\tswitch {\n\tcase serviceMode.Replicated != nil:\n\t\tserviceMode.Replicated.Replicas = &scale\n\tcase serviceMode.ReplicatedJob != nil:\n\t\tserviceMode.ReplicatedJob.TotalCompletions = &scale\n\tdefault:\n\t\treturn nil, errors.New(\"scale can only be used with replicated or replicated-job mode\")\n\t}\n\n\tresponse, err := apiClient.ServiceUpdate(ctx, res.Service.ID, client.ServiceUpdateOptions{\n\t\tVersion: res.Service.Version,\n\t\tSpec:    res.Service.Spec,\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn response.Warnings, nil\n}\n\n// completeScaleArgs returns a completion function for the args of the scale command.\n// It completes service names followed by \"=\", suppressing the trailing space.\nfunc completeScaleArgs(dockerCli command.Cli) func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {\n\treturn func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {\n\t\t// reuse the existing logic for configurable completion of service names and IDs.\n\t\tcompletions, directive := completeServiceNames(dockerCli)(cmd, args, toComplete)","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/docker/cli/blob/e9452d6e785f6e365712b9d71bd7517591773c86/cli/command/service/scale.go#L90-L126","documentation":"Emitted by `docker service scale`. runServiceScale (scale.go:95-109) inspects the service and only knows how to set Replicated.Replicas or ReplicatedJob.TotalCompletions; if the service's mode is global or global-job (the default branch of the switch), scaling is meaningless because those modes run exactly one task per matching node, so the CLI refuses.","triggerScenarios":"`docker service scale <svc>=N` against a service created with `--mode global` or `--mode global-job`; the ServiceInspect result has neither Spec.Mode.Replicated nor Spec.Mode.ReplicatedJob set.","commonSituations":"Trying to scale monitoring/logging agents (node-exporter, fluentd) that are intentionally deployed global; compose stacks with `deploy.mode: global`; confusing global mode (one task per node) with replicated mode.","solutions":["Check the mode with `docker service inspect --format '{{json .Spec.Mode}}' <svc>`; if global, scaling is per-node by design — add/remove nodes or use placement constraints instead","If the service should be replicated, recreate it: `docker service rm <svc>` then `docker service create --mode replicated --replicas N ...` (mode cannot be changed on update)","For jobs, use `--mode replicated-job` so TotalCompletions can be scaled"],"exampleFix":"# before\ndocker service create --mode global --name agent myimg\ndocker service scale agent=3   # fails\n\n# after\ndocker service create --mode replicated --replicas 1 --name agent myimg\ndocker service scale agent=3","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["swarm","service","scale","service-mode"],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}