{"id":"45d9278a6affa42b","repo":"docker/cli","slug":"replicas-can-only-be-used-with-replicated-or-repli-45d927","errorCode":null,"errorMessage":"replicas can only be used with replicated or replicated-job mode","messagePattern":"replicas can only be used with replicated or replicated-job mode","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/compose/convert/service.go","lineNumber":637,"sourceCode":"\tfor name, value := range source {\n\t\tswitch value {\n\t\tcase nil:\n\t\t\toutput = append(output, name)\n\t\tdefault:\n\t\t\toutput = append(output, name+\"=\"+*value)\n\t\t}\n\t}\n\tsort.Strings(output)\n\treturn output\n}\n\nfunc convertDeployMode(mode string, replicas *uint64) (swarm.ServiceMode, error) {\n\tserviceMode := swarm.ServiceMode{}\n\n\tswitch mode {\n\tcase \"global-job\":\n\t\tif replicas != nil {\n\t\t\treturn serviceMode, errors.New(\"replicas can only be used with replicated or replicated-job mode\")\n\t\t}\n\t\tserviceMode.GlobalJob = &swarm.GlobalJob{}\n\tcase \"global\":\n\t\tif replicas != nil {\n\t\t\treturn serviceMode, errors.New(\"replicas can only be used with replicated or replicated-job mode\")\n\t\t}\n\t\tserviceMode.Global = &swarm.GlobalService{}\n\tcase \"replicated-job\":\n\t\tserviceMode.ReplicatedJob = &swarm.ReplicatedJob{\n\t\t\tMaxConcurrent:    replicas,\n\t\t\tTotalCompletions: replicas,\n\t\t}\n\tcase \"replicated\", \"\":\n\t\tserviceMode.Replicated = &swarm.ReplicatedService{Replicas: replicas}\n\tdefault:\n\t\treturn serviceMode, fmt.Errorf(\"unknown mode: %s\", mode)\n\t}\n\treturn serviceMode, nil","sourceCodeStart":619,"sourceCodeEnd":655,"githubUrl":"https://github.com/docker/cli/blob/e9452d6e785f6e365712b9d71bd7517591773c86/cli/compose/convert/service.go#L619-L655","documentation":"Raised by convertDeployMode when a compose service declares `deploy.mode: global-job` while also setting `deploy.replicas`. A global-job runs exactly one task per matching node, so a replica count is contradictory; the converter rejects the combination instead of ignoring the replicas.","triggerScenarios":"`docker stack deploy` of a compose file with `deploy: {mode: global-job, replicas: N}`. Any non-nil replicas pointer with mode 'global-job' triggers it during service conversion.","commonSituations":"Switching a service's mode from replicated-job to global-job and leaving `replicas:` behind; compose override files where a base file sets replicas and an override changes the mode; misunderstanding that global-job scales per-node, not by count.","solutions":["Remove `replicas:` from the service's deploy block when using mode: global-job","If you want a fixed number of job tasks, use `mode: replicated-job` and keep replicas","Run `docker compose config` on merged files to locate the stray replicas key"],"exampleFix":"# before\ndeploy:\n  mode: global-job\n  replicas: 3\n# after\ndeploy:\n  mode: replicated-job\n  replicas: 3","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["docker-cli","compose","swarm","deploy-mode","job"],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}