@@ -50,7 +50,6 @@ type runOptions struct {
5050 Detach bool
5151 Remove bool
5252 noTty bool
53- tty bool
5453 interactive bool
5554 user string
5655 workdir string
@@ -155,6 +154,10 @@ func runCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) *
155154 buildOpts := buildOptions {
156155 ProjectOptions : p ,
157156 }
157+ // We remove the attribute from the option struct and use a dedicated var, to limit confusion and avoid anyone to use options.tty.
158+ // The tty flag is here for convenience and let user do "docker compose run -it" the same way as they use the "docker run" command.
159+ var ttyFlag bool
160+
158161 cmd := & cobra.Command {
159162 Use : "run [OPTIONS] SERVICE [COMMAND] [ARGS...]" ,
160163 Short : "Run a one-off command on a service" ,
@@ -178,7 +181,7 @@ func runCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) *
178181 if cmd .Flags ().Changed ("no-TTY" ) {
179182 return fmt .Errorf ("--tty and --no-TTY can't be used together" )
180183 } else {
181- options .noTty = ! options . tty
184+ options .noTty = ! ttyFlag
182185 }
183186 }
184187 if options .quiet {
@@ -238,7 +241,7 @@ func runCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) *
238241 flags .BoolVar (& options .removeOrphans , "remove-orphans" , false , "Remove containers for services not defined in the Compose file" )
239242
240243 cmd .Flags ().BoolVarP (& options .interactive , "interactive" , "i" , true , "Keep STDIN open even if not attached" )
241- cmd .Flags ().BoolVarP (& options . tty , "tty" , "t" , true , "Allocate a pseudo-TTY" )
244+ cmd .Flags ().BoolVarP (& ttyFlag , "tty" , "t" , true , "Allocate a pseudo-TTY" )
242245 cmd .Flags ().MarkHidden ("tty" ) //nolint:errcheck
243246
244247 flags .SetNormalizeFunc (normalizeRunFlags )
0 commit comments