{"record":{"id":"f78ff286a795e16e","repo":"docker/compose","slug":"cannot-specify-deprecated-no-ansi-and-ansi","errorCode":null,"errorMessage":"cannot specify DEPRECATED \"--no-ansi\" and \"--ansi\". Please use only \"--ansi\"","messagePattern":"cannot specify DEPRECATED \"--no-ansi\" and \"--ansi\"\\. Please use only \"--ansi\"","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/compose/compose.go","lineNumber":488,"sourceCode":"\t\t\t\tif parentPrerun != nil {\n\t\t\t\t\terr := parentPrerun(cmd, args)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn err\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif verbose {\n\t\t\t\tlogrus.SetLevel(logrus.TraceLevel)\n\t\t\t}\n\n\t\t\terr := setEnvWithDotEnv(opts, dockerCli)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tif noAnsi {\n\t\t\t\tif ansi != \"auto\" {\n\t\t\t\t\treturn errors.New(`cannot specify DEPRECATED \"--no-ansi\" and \"--ansi\". Please use only \"--ansi\"`)\n\t\t\t\t}\n\t\t\t\tansi = \"never\"\n\t\t\t\tfmt.Fprint(os.Stderr, \"option '--no-ansi' is DEPRECATED ! Please use '--ansi' instead.\\n\")\n\t\t\t}\n\t\t\tif v, ok := os.LookupEnv(\"COMPOSE_ANSI\"); ok && !cmd.Flags().Changed(\"ansi\") {\n\t\t\t\tansi = v\n\t\t\t}\n\t\t\tformatter.SetANSIMode(dockerCli, ansi)\n\n\t\t\tif noColor, ok := os.LookupEnv(\"NO_COLOR\"); ok && noColor != \"\" {\n\t\t\t\tdisplay.NoColor()\n\t\t\t\tformatter.SetANSIMode(dockerCli, formatter.Never)\n\t\t\t}\n\n\t\t\tswitch ansi {\n\t\t\tcase \"never\":\n\t\t\t\tdisplay.Mode = display.ModePlain\n\t\t\tcase \"always\":","sourceCodeStart":470,"sourceCodeEnd":506,"githubUrl":"https://github.com/docker/compose/blob/ddc4b044b62e9f715212ea4143fa830fac76382f/cmd/compose/compose.go#L470-L506","documentation":"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.","triggerScenarios":"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.","commonSituations":"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\").","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."],"exampleFix":"# before\ndocker compose --no-ansi --ansi never up\n\n# after\ndocker compose --ansi never up","handlingStrategy":"validation","validationCode":"# before invoking, ensure only one of the flags is present\nif printf '%s\\n' \"$@\" | grep -q -- '--no-ansi' && printf '%s\\n' \"$@\" | grep -q -- '--ansi'; then\n  echo \"remove --no-ansi; use --ansi only\" >&2\n  exit 1\nfi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["cli","flags","deprecated","ansi"],"backgroundTag":null,"analyzedSha":"ddc4b044b62e9f715212ea4143fa830fac76382f","analyzedAt":"2026-08-15T13:31:42.319Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}