diff --git a/cmd/compose/exec.go b/cmd/compose/exec.go index 23169156398..a978b65ff3f 100644 --- a/cmd/compose/exec.go +++ b/cmd/compose/exec.go @@ -29,6 +29,7 @@ import ( "github.com/docker/compose/v2/pkg/compose" "github.com/sirupsen/logrus" "github.com/spf13/cobra" + "github.com/spf13/pflag" ) type execOpts struct { @@ -81,7 +82,7 @@ func execCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) runCmd.Flags().IntVar(&opts.index, "index", 0, "Index of the container if service has multiple replicas") runCmd.Flags().BoolVarP(&opts.privileged, "privileged", "", false, "Give extended privileges to the process") runCmd.Flags().StringVarP(&opts.user, "user", "u", "", "Run the command as this user") - runCmd.Flags().BoolVarP(&opts.noTty, "no-TTY", "T", !dockerCli.Out().IsTerminal(), "Disable pseudo-TTY allocation. By default `docker compose exec` allocates a TTY.") + runCmd.Flags().BoolVarP(&opts.noTty, "no-tty", "T", !dockerCli.Out().IsTerminal(), "Disable pseudo-TTY allocation. By default `docker compose exec` allocates a TTY.") runCmd.Flags().StringVarP(&opts.workingDir, "workdir", "w", "", "Path to workdir directory for this command") runCmd.Flags().BoolVarP(&opts.interactive, "interactive", "i", true, "Keep STDIN open even if not attached") @@ -90,6 +91,12 @@ func execCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) runCmd.Flags().MarkHidden("tty") //nolint:errcheck runCmd.Flags().SetInterspersed(false) + runCmd.Flags().SetNormalizeFunc(func(f *pflag.FlagSet, name string) pflag.NormalizedName { + if name == "no-TTY" { // legacy + name = "no-tty" + } + return pflag.NormalizedName(name) + }) return runCmd } diff --git a/docs/reference/compose_exec.md b/docs/reference/compose_exec.md index 8b54def472e..ab3bbbe3526 100644 --- a/docs/reference/compose_exec.md +++ b/docs/reference/compose_exec.md @@ -6,6 +6,12 @@ This is the equivalent of `docker exec` targeting a Compose service. With this subcommand, you can run arbitrary commands in your services. Commands allocate a TTY by default, so you can use a command such as `docker compose exec web sh` to get an interactive prompt. +By default, Compose will enter container in interactive mode and allocate a TTY, while the equivalent `docker exec` +command requires passing `--interactive --tty` flags to get the same behavior. Compose also support those two flags +to offer a smooth migration between commands, whenever they are no-op by default. Still, `interactive` can be used to +force disabling interactive mode (`--interactive=false`), typically when `docker compose exec` command is used inside +a script. + ### Options | Name | Type | Default | Description | @@ -14,7 +20,7 @@ you can use a command such as `docker compose exec web sh` to get an interactive | `--dry-run` | `bool` | | Execute command in dry run mode | | `-e`, `--env` | `stringArray` | | Set environment variables | | `--index` | `int` | `0` | Index of the container if service has multiple replicas | -| `-T`, `--no-TTY` | `bool` | `true` | Disable pseudo-TTY allocation. By default `docker compose exec` allocates a TTY. | +| `-T`, `--no-tty` | `bool` | `true` | Disable pseudo-TTY allocation. By default `docker compose exec` allocates a TTY. | | `--privileged` | `bool` | | Give extended privileges to the process | | `-u`, `--user` | `string` | | Run the command as this user | | `-w`, `--workdir` | `string` | | Path to workdir directory for this command | @@ -28,3 +34,9 @@ This is the equivalent of `docker exec` targeting a Compose service. With this subcommand, you can run arbitrary commands in your services. Commands allocate a TTY by default, so you can use a command such as `docker compose exec web sh` to get an interactive prompt. + +By default, Compose will enter container in interactive mode and allocate a TTY, while the equivalent `docker exec` +command requires passing `--interactive --tty` flags to get the same behavior. Compose also support those two flags +to offer a smooth migration between commands, whenever they are no-op by default. Still, `interactive` can be used to +force disabling interactive mode (`--interactive=false`), typically when `docker compose exec` command is used inside +a script. \ No newline at end of file diff --git a/docs/reference/docker_compose_exec.yaml b/docs/reference/docker_compose_exec.yaml index b2a1cf20685..749682c96fb 100644 --- a/docs/reference/docker_compose_exec.yaml +++ b/docs/reference/docker_compose_exec.yaml @@ -5,6 +5,12 @@ long: |- With this subcommand, you can run arbitrary commands in your services. Commands allocate a TTY by default, so you can use a command such as `docker compose exec web sh` to get an interactive prompt. + + By default, Compose will enter container in interactive mode and allocate a TTY, while the equivalent `docker exec` + command requires passing `--interactive --tty` flags to get the same behavior. Compose also support those two flags + to offer a smooth migration between commands, whenever they are no-op by default. Still, `interactive` can be used to + force disabling interactive mode (`--interactive=false`), typically when `docker compose exec` command is used inside + a script. usage: docker compose exec [OPTIONS] SERVICE COMMAND [ARGS...] pname: docker compose plink: docker_compose.yaml @@ -52,7 +58,7 @@ options: experimentalcli: false kubernetes: false swarm: false - - option: no-TTY + - option: no-tty shorthand: T value_type: bool default_value: "true"