{"record":{"id":"11d84af625c4b725","repo":"docker/compose","slug":"force-recreate-and-no-recreate-are-incompatibl-11d84a","errorCode":null,"errorMessage":"--force-recreate and --no-recreate are incompatible","messagePattern":"--force-recreate and --no-recreate are incompatible","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/compose/up.go","lineNumber":220,"sourceCode":"\t\t\treturn fmt.Errorf(\"--wait cannot be combined with --abort-on-container-exit, --attach or --attach-dependencies\")\n\t\t}\n\t\tup.Detach = true\n\t}\n\tif create.Build && create.noBuild {\n\t\treturn fmt.Errorf(\"--build and --no-build are incompatible\")\n\t}\n\tif up.Detach && (up.attachDependencies || up.cascadeStop || up.cascadeFail || len(up.attach) > 0 || up.watch) {\n\t\tif up.wait {\n\t\t\treturn fmt.Errorf(\"--wait cannot be combined with --abort-on-container-exit, --abort-on-container-failure, --attach, --attach-dependencies or --watch\")\n\t\t} else {\n\t\t\treturn fmt.Errorf(\"--detach cannot be combined with --abort-on-container-exit, --abort-on-container-failure, --attach, --attach-dependencies or --watch\")\n\t\t}\n\t}\n\tif create.noInherit && create.noRecreate {\n\t\treturn fmt.Errorf(\"--no-recreate and --renew-anon-volumes are incompatible\")\n\t}\n\tif create.forceRecreate && create.noRecreate {\n\t\treturn fmt.Errorf(\"--force-recreate and --no-recreate are incompatible\")\n\t}\n\tif create.recreateDeps && create.noRecreate {\n\t\treturn fmt.Errorf(\"--always-recreate-deps and --no-recreate are incompatible\")\n\t}\n\tif create.noBuild && up.watch {\n\t\treturn fmt.Errorf(\"--no-build and --watch are incompatible\")\n\t}\n\treturn nil\n}\n\n//nolint:gocyclo\nfunc runUp(\n\tctx context.Context,\n\tdockerCli command.Cli,\n\tbackendOptions *BackendOptions,\n\tcreateOptions createOptions,\n\tupOptions upOptions,\n\tbuildOptions buildOptions,","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/docker/compose/blob/ddc4b044b62e9f715212ea4143fa830fac76382f/cmd/compose/up.go#L202-L238","documentation":"Returned by validateFlags when create.forceRecreate (--force-recreate) and create.noRecreate (--no-recreate) are both set. One demands containers be recreated even if config is unchanged; the other forbids recreation even if config changed. Direct contradiction, rejected during PreRunE before any docker call.","triggerScenarios":"`docker compose up --force-recreate --no-recreate`; same pair via shared createOptions in `create`; CI pipelines that combine a 'always clean' flag set with a 'preserve state' flag set.","commonSituations":"Copy-pasted up commands from two different runbooks merged into one; a wrapper adding --no-recreate to protect databases while another layer adds --force-recreate to apply image updates.","solutions":["Choose one: `--force-recreate` to apply changes, or `--no-recreate` to preserve containers (default recreates only on config change — often you need neither).","Refactor flag assembly so recreate-policy flags come from a single mutually exclusive variable."],"exampleFix":"# before\ndocker compose up --force-recreate --no-recreate\n\n# after\ndocker compose up --force-recreate","handlingStrategy":"validation","validationCode":"if [[ \"$UP_FLAGS\" == *--force-recreate* && \"$UP_FLAGS\" == *--no-recreate* ]]; then\n  echo 'pick one recreate policy' >&2; exit 2\nfi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default to neither flag: Compose recreates on config change automatically.","Keep recreate policy in a single script variable."],"tags":["cli","up","flags","validation","recreate","compose"],"backgroundTag":null,"analyzedSha":"ddc4b044b62e9f715212ea4143fa830fac76382f","analyzedAt":"2026-08-15T13:31:42.319Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}