docker/compose · error

--force-recreate and --no-recreate are incompatible

Error message

--force-recreate and --no-recreate are incompatible

What it means

`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.

Source

Thrown at cmd/compose/create.go:69

	scale         []string
	AssumeYes     bool
}

func createCommand(p *ProjectOptions, dockerCli command.Cli, backendOptions *BackendOptions) *cobra.Command {
	opts := createOptions{}
	buildOpts := buildOptions{
		ProjectOptions: p,
	}
	cmd := &cobra.Command{
		Use:   "create [OPTIONS] [SERVICE...]",
		Short: "Creates containers for a service",
		PreRunE: AdaptCmd(func(ctx context.Context, cmd *cobra.Command, args []string) error {
			opts.pullChanged = cmd.Flags().Changed("pull")
			if opts.Build && opts.noBuild {
				return fmt.Errorf("--build and --no-build are incompatible")
			}
			if opts.forceRecreate && opts.noRecreate {
				return fmt.Errorf("--force-recreate and --no-recreate are incompatible")
			}
			return nil
		}),
		RunE: p.WithServices(dockerCli, func(ctx context.Context, project *types.Project, services []string) error {
			return runCreate(ctx, dockerCli, backendOptions, opts, buildOpts, project, services)
		}),
		ValidArgsFunction: completeServiceNames(dockerCli, p),
	}
	flags := cmd.Flags()
	flags.BoolVar(&opts.Build, "build", false, "Build images before starting containers")
	flags.BoolVar(&opts.noBuild, "no-build", false, "Don't build an image, even if it's policy")
	flags.StringVar(&opts.Pull, "pull", "policy", `Pull image before running ("always"|"missing"|"never"|"build")`)
	flags.BoolVar(&opts.quietPull, "quiet-pull", false, "Pull without printing progress information")
	flags.BoolVar(&opts.forceRecreate, "force-recreate", false, "Recreate containers even if their configuration and image haven't changed")
	flags.BoolVar(&opts.noRecreate, "no-recreate", false, "If containers already exist, don't recreate them. Incompatible with --force-recreate.")
	flags.BoolVar(&opts.removeOrphans, "remove-orphans", false, "Remove containers for services not defined in the Compose file")
	flags.StringArrayVar(&opts.scale, "scale", []string{}, "Scale SERVICE to NUM instances. Overrides the `scale` setting in the Compose file if present.")
	flags.BoolVarP(&opts.AssumeYes, "yes", "y", false, `Assume "yes" as answer to all prompts and run non-interactively`)

View on GitHub (pinned to ddc4b044b6)

Solutions

  1. Remove one flag based on the desired recreate behavior.
  2. In scripts, make the recreate flags mutually exclusive (if/else) rather than independent booleans.
  3. Audit wrapper scripts and aliases that append flags automatically.

Example fix

# before
docker compose create --force-recreate --no-recreate

# after
docker compose create --force-recreate
Defensive patterns

Strategy: validation

Validate before calling

# bash: mutually exclusive recreate policy
if [ "$FORCE" = true ] && [ "$NOREC" = true ]; then echo "pick one: --force-recreate or --no-recreate" >&2; exit 2; fi
docker compose create $([ "$FORCE" = true ] && echo --force-recreate) $([ "$NOREC" = true ] && echo --no-recreate)

Prevention

When it happens

Trigger: Running `docker compose create --force-recreate --no-recreate` or a script that forwards both flags unconditionally from separate boolean options.

Common situations: 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.

Related errors


AI-assisted analysis of docker/compose@ddc4b044b6 (2026-08-15). Data as JSON: /api/errors/9be7b58fb105ce80. Report an issue: GitHub.