docker/compose · error
cannot specify DEPRECATED "--no-ansi" and "--ansi". Please u
Error message
cannot specify DEPRECATED "--no-ansi" and "--ansi". Please use only "--ansi"
What it means
The root-level persistent flags --no-ansi and --ansi are mutually exclusive; the former is deprecated in favor of the latter. During CLI initialization in cmd/compose/compose.go, after dotenv loading, the code checks the ansi mode string: if --no-ansi was passed while --ansi was explicitly set to anything other than the default "auto", the command aborts. Passing --no-ansi alone is still accepted and internally maps to --ansi never with a deprecation warning on stderr.
Source
Thrown at cmd/compose/compose.go:488
if parentPrerun != nil {
err := parentPrerun(cmd, args)
if err != nil {
return err
}
}
}
if verbose {
logrus.SetLevel(logrus.TraceLevel)
}
err := setEnvWithDotEnv(opts, dockerCli)
if err != nil {
return err
}
if noAnsi {
if ansi != "auto" {
return errors.New(`cannot specify DEPRECATED "--no-ansi" and "--ansi". Please use only "--ansi"`)
}
ansi = "never"
fmt.Fprint(os.Stderr, "option '--no-ansi' is DEPRECATED ! Please use '--ansi' instead.\n")
}
if v, ok := os.LookupEnv("COMPOSE_ANSI"); ok && !cmd.Flags().Changed("ansi") {
ansi = v
}
formatter.SetANSIMode(dockerCli, ansi)
if noColor, ok := os.LookupEnv("NO_COLOR"); ok && noColor != "" {
display.NoColor()
formatter.SetANSIMode(dockerCli, formatter.Never)
}
switch ansi {
case "never":
display.Mode = display.ModePlain
case "always":View on GitHub (pinned to ddc4b044b6)
Solutions
- Remove --no-ansi from the command line and keep only --ansi (e.g. --ansi never replaces --no-ansi).
- If the flag comes from a script variable, audit and clean the variable so only --ansi remains.
- In automation that cannot edit the invocation, set the COMPOSE_ANSI environment variable (e.g. COMPOSE_ANSI=never) instead of passing either flag, since COMPOSE_ANSI is applied when --ansi was not changed.
Example fix
# before docker compose --no-ansi --ansi never up # after docker compose --ansi never up
Defensive patterns
Strategy: validation
Validate before calling
# before invoking, ensure only one of the flags is present if printf '%s\n' "$@" | grep -q -- '--no-ansi' && printf '%s\n' "$@" | grep -q -- '--ansi'; then echo "remove --no-ansi; use --ansi only" >&2 exit 1 fi
Prevention
- Standardize CI scripts on --ansi <mode> only and grep repositories for stray --no-ansi.
- Prefer the COMPOSE_ANSI environment variable in automation to avoid flag conflicts entirely.
When it happens
Trigger: Running any docker compose command that combines both flags, e.g. `docker compose --no-ansi --ansi never up`, or `docker compose --no-ansi --ansi=always ps`. It only fires when --ansi differs from its default value "auto", so `--no-ansi` plus an explicitly-set `--ansi auto` still passes.
Common situations: CI pipelines or shell scripts written for older Compose versions that used --no-ansi, later amended to add --ansi without removing the old flag; wrapper scripts that concatenate flag variables (e.g. FLAGS="--no-ansi $ANSI_FLAGS").
Related errors
- cannot specify DEPRECATED "--workdir" and "--project-directo
- can't use --progress plain while ANSI support is forced
- --index requires one service to be selected
- cannot combine --attach and --attach-dependencies
- can't use --progress tty while ANSI support is disabled
AI-assisted analysis of docker/compose@ddc4b044b6 (2026-08-15).
Data as JSON: /api/errors/f78ff286a795e16e.
Report an issue: GitHub.