docker/compose · error
--force-recreate and --no-recreate are incompatible
Error message
--force-recreate and --no-recreate are incompatible
What it means
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.
Source
Thrown at cmd/compose/up.go:220
return fmt.Errorf("--wait cannot be combined with --abort-on-container-exit, --attach or --attach-dependencies")
}
up.Detach = true
}
if create.Build && create.noBuild {
return fmt.Errorf("--build and --no-build are incompatible")
}
if up.Detach && (up.attachDependencies || up.cascadeStop || up.cascadeFail || len(up.attach) > 0 || up.watch) {
if up.wait {
return fmt.Errorf("--wait cannot be combined with --abort-on-container-exit, --abort-on-container-failure, --attach, --attach-dependencies or --watch")
} else {
return fmt.Errorf("--detach cannot be combined with --abort-on-container-exit, --abort-on-container-failure, --attach, --attach-dependencies or --watch")
}
}
if create.noInherit && create.noRecreate {
return fmt.Errorf("--no-recreate and --renew-anon-volumes are incompatible")
}
if create.forceRecreate && create.noRecreate {
return fmt.Errorf("--force-recreate and --no-recreate are incompatible")
}
if create.recreateDeps && create.noRecreate {
return fmt.Errorf("--always-recreate-deps and --no-recreate are incompatible")
}
if create.noBuild && up.watch {
return fmt.Errorf("--no-build and --watch are incompatible")
}
return nil
}
//nolint:gocyclo
func runUp(
ctx context.Context,
dockerCli command.Cli,
backendOptions *BackendOptions,
createOptions createOptions,
upOptions upOptions,
buildOptions buildOptions,View on GitHub (pinned to ddc4b044b6)
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.
Example fix
# before docker compose up --force-recreate --no-recreate # after docker compose up --force-recreate
Defensive patterns
Strategy: validation
Validate before calling
if [[ "$UP_FLAGS" == *--force-recreate* && "$UP_FLAGS" == *--no-recreate* ]]; then echo 'pick one recreate policy' >&2; exit 2 fi
Prevention
- Default to neither flag: Compose recreates on config change automatically.
- Keep recreate policy in a single script variable.
When it happens
Trigger: `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.
Common situations: 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.
Related errors
- --always-recreate-deps and --no-recreate are incompatible
- --wait-timeout must be a non-negative integer
- --abort-on-container-failure cannot be combined with --abort
- --wait cannot be combined with --abort-on-container-exit, --
- --build and --no-build are incompatible
AI-assisted analysis of docker/compose@ddc4b044b6 (2026-08-15).
Data as JSON: /api/errors/11d84af625c4b725.
Report an issue: GitHub.