{"record":{"id":"9be7b58fb105ce80","repo":"docker/compose","slug":"force-recreate-and-no-recreate-are-incompatibl","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/create.go","lineNumber":69,"sourceCode":"\tscale         []string\n\tAssumeYes     bool\n}\n\nfunc createCommand(p *ProjectOptions, dockerCli command.Cli, backendOptions *BackendOptions) *cobra.Command {\n\topts := createOptions{}\n\tbuildOpts := buildOptions{\n\t\tProjectOptions: p,\n\t}\n\tcmd := &cobra.Command{\n\t\tUse:   \"create [OPTIONS] [SERVICE...]\",\n\t\tShort: \"Creates containers for a service\",\n\t\tPreRunE: AdaptCmd(func(ctx context.Context, cmd *cobra.Command, args []string) error {\n\t\t\topts.pullChanged = cmd.Flags().Changed(\"pull\")\n\t\t\tif opts.Build && opts.noBuild {\n\t\t\t\treturn fmt.Errorf(\"--build and --no-build are incompatible\")\n\t\t\t}\n\t\t\tif opts.forceRecreate && opts.noRecreate {\n\t\t\t\treturn fmt.Errorf(\"--force-recreate and --no-recreate are incompatible\")\n\t\t\t}\n\t\t\treturn nil\n\t\t}),\n\t\tRunE: p.WithServices(dockerCli, func(ctx context.Context, project *types.Project, services []string) error {\n\t\t\treturn runCreate(ctx, dockerCli, backendOptions, opts, buildOpts, project, services)\n\t\t}),\n\t\tValidArgsFunction: completeServiceNames(dockerCli, p),\n\t}\n\tflags := cmd.Flags()\n\tflags.BoolVar(&opts.Build, \"build\", false, \"Build images before starting containers\")\n\tflags.BoolVar(&opts.noBuild, \"no-build\", false, \"Don't build an image, even if it's policy\")\n\tflags.StringVar(&opts.Pull, \"pull\", \"policy\", `Pull image before running (\"always\"|\"missing\"|\"never\"|\"build\")`)\n\tflags.BoolVar(&opts.quietPull, \"quiet-pull\", false, \"Pull without printing progress information\")\n\tflags.BoolVar(&opts.forceRecreate, \"force-recreate\", false, \"Recreate containers even if their configuration and image haven't changed\")\n\tflags.BoolVar(&opts.noRecreate, \"no-recreate\", false, \"If containers already exist, don't recreate them. Incompatible with --force-recreate.\")\n\tflags.BoolVar(&opts.removeOrphans, \"remove-orphans\", false, \"Remove containers for services not defined in the Compose file\")\n\tflags.StringArrayVar(&opts.scale, \"scale\", []string{}, \"Scale SERVICE to NUM instances. Overrides the `scale` setting in the Compose file if present.\")\n\tflags.BoolVarP(&opts.AssumeYes, \"yes\", \"y\", false, `Assume \"yes\" as answer to all prompts and run non-interactively`)","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/docker/compose/blob/ddc4b044b62e9f715212ea4143fa830fac76382f/cmd/compose/create.go#L51-L87","documentation":"`docker compose create` rejects `--force-recreate` together with `--no-recreate`. Force-recreate demands containers be rebuilt even if config is unchanged, while no-recreate demands the opposite; the PreRunE validation refuses the contradiction.","triggerScenarios":"Running `docker compose create --force-recreate --no-recreate` or a script that forwards both flags unconditionally from separate boolean options.","commonSituations":"CI matrices or Makefile targets that string together every recreate flag 'to be safe'; parameterized deploy scripts where the two booleans were never made mutually exclusive.","solutions":["Remove one flag based on the desired recreate behavior.","In scripts, make the recreate flags mutually exclusive (if/else) rather than independent booleans.","Audit wrapper scripts and aliases that append flags automatically."],"exampleFix":"# before\ndocker compose create --force-recreate --no-recreate\n\n# after\ndocker compose create --force-recreate","handlingStrategy":"validation","validationCode":"# bash: mutually exclusive recreate policy\nif [ \"$FORCE\" = true ] && [ \"$NOREC\" = true ]; then echo \"pick one: --force-recreate or --no-recreate\" >&2; exit 2; fi\ndocker compose create $([ \"$FORCE\" = true ] && echo --force-recreate) $([ \"$NOREC\" = true ] && echo --no-recreate)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never string together recreate flags 'for safety'; they are opposites.","Encode recreate behavior as one enum in deployment scripts."],"tags":["cli","create","recreate","flags","conflict"],"backgroundTag":null,"analyzedSha":"ddc4b044b62e9f715212ea4143fa830fac76382f","analyzedAt":"2026-08-15T13:31:42.319Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}