{"record":{"id":"a41af5ac3cfe3c5f","repo":"docker/compose","slug":"tty-and-no-tty-can-t-be-used-together","errorCode":null,"errorMessage":"--tty and --no-tty can't be used together","messagePattern":"--tty and --no-tty can't be used together","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/compose/run.go","lineNumber":182,"sourceCode":"\t\tArgs:  cobra.MinimumNArgs(1),\n\t\tPreRunE: AdaptCmd(func(ctx context.Context, cmd *cobra.Command, args []string) error {\n\t\t\toptions.Service = args[0]\n\t\t\tif len(args) > 1 {\n\t\t\t\toptions.Command = args[1:]\n\t\t\t}\n\t\t\tif len(options.publish) > 0 && options.servicePorts {\n\t\t\t\treturn fmt.Errorf(\"--service-ports and --publish are incompatible\")\n\t\t\t}\n\t\t\tif cmd.Flags().Changed(\"entrypoint\") {\n\t\t\t\tcommand, err := shellwords.Parse(options.entrypoint)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t\toptions.entrypointCmd = command\n\t\t\t}\n\t\t\tif cmd.Flags().Changed(\"tty\") {\n\t\t\t\tif cmd.Flags().Changed(\"no-tty\") {\n\t\t\t\t\treturn fmt.Errorf(\"--tty and --no-tty can't be used together\")\n\t\t\t\t} else {\n\t\t\t\t\toptions.noTty = !ttyFlag\n\t\t\t\t}\n\t\t\t} else if !cmd.Flags().Changed(\"no-tty\") && !cmd.Flags().Changed(\"interactive\") && !dockerCli.In().IsTerminal() {\n\t\t\t\t// while `docker run` requires explicit `-it` flags, Compose enables interactive mode and TTY by default\n\t\t\t\t// but when compose is used from a script that has stdin piped from another command, we just can't\n\t\t\t\t// Here, we detect we run \"by default\" (user didn't passed explicit flags) and disable TTY allocation if\n\t\t\t\t// we don't have an actual terminal to attach to for interactive mode\n\t\t\t\toptions.noTty = true\n\t\t\t}\n\n\t\t\tif options.quiet {\n\t\t\t\tdisplay.Mode = display.ModeQuiet\n\t\t\t\tbackendOptions.Add(compose.WithEventProcessor(display.Quiet()))\n\t\t\t}\n\t\t\tcreateOpts.pullChanged = cmd.Flags().Changed(\"pull\")\n\t\t\treturn nil\n\t\t}),","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/docker/compose/blob/ddc4b044b62e9f715212ea4143fa830fac76382f/cmd/compose/run.go#L164-L200","documentation":"`docker compose run` has both `--tty` and `--no-tty` flags; setting both in the same invocation is rejected because they directly contradict. The check uses Flags().Changed so even `--tty=false --no-tty=false` (both explicitly set) triggers the error.","triggerScenarios":"Running `docker compose run --tty --no-tty web`, or any invocation where both flags appear on the command line regardless of their values.","commonSituations":"Scripts templating both flags from independent booleans (`--tty=$TTY --no-tty=$NOTTY`); users adding --no-tty for piped input while --tty is already set by an alias or wrapper.","solutions":["Pass exactly one of `--tty` or `--no-tty`.","Rely on compose's auto-detection: with no flags it enables TTY only when stdin is a terminal.","In scripts, branch on a single boolean and emit only the corresponding flag."],"exampleFix":"# before\ndocker compose run --tty --no-tty web sh\n\n# after\ndocker compose run --no-tty web sh","handlingStrategy":"validation","validationCode":"# bash: single tty policy\nTTY_ARGS=()\ncase \"${TTY_MODE:-auto}\" in tty) TTY_ARGS=(--tty);; no-tty) TTY_ARGS=(--no-tty);; auto) ;; *) echo \"tty mode must be tty|no-tty|auto\" >&2; exit 2;; esac\ndocker compose run \"${TTY_ARGS[@]}\" web","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Let compose auto-detect TTY when flags are unnecessary.","Never template both --tty and --no-tty from separate booleans."],"tags":["cli","run","tty","flags","conflict"],"backgroundTag":null,"analyzedSha":"ddc4b044b62e9f715212ea4143fa830fac76382f","analyzedAt":"2026-08-15T13:31:42.319Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}