@@ -50,7 +50,6 @@ type runOptions struct {
50
50
Detach bool
51
51
Remove bool
52
52
noTty bool
53
- tty bool
54
53
interactive bool
55
54
user string
56
55
workdir string
@@ -155,6 +154,10 @@ func runCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) *
155
154
buildOpts := buildOptions {
156
155
ProjectOptions : p ,
157
156
}
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
+
158
161
cmd := & cobra.Command {
159
162
Use : "run [OPTIONS] SERVICE [COMMAND] [ARGS...]" ,
160
163
Short : "Run a one-off command on a service" ,
@@ -178,7 +181,7 @@ func runCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) *
178
181
if cmd .Flags ().Changed ("no-TTY" ) {
179
182
return fmt .Errorf ("--tty and --no-TTY can't be used together" )
180
183
} else {
181
- options .noTty = ! options . tty
184
+ options .noTty = ! ttyFlag
182
185
}
183
186
}
184
187
if options .quiet {
@@ -238,7 +241,7 @@ func runCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) *
238
241
flags .BoolVar (& options .removeOrphans , "remove-orphans" , false , "Remove containers for services not defined in the Compose file" )
239
242
240
243
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" )
242
245
cmd .Flags ().MarkHidden ("tty" ) //nolint:errcheck
243
246
244
247
flags .SetNormalizeFunc (normalizeRunFlags )
0 commit comments