Skip to content

Compose: Undocumented flag --interactive for docker compose exec #23352

Description

@polarathene

Is this a docs issue?

  • My issue is about the documentation content or website

Type of issue

Information is incorrect

Description

When responding to a contribution, I noticed that the docs for docker compose exec have no -i / --interactive flag (docker exec, docker run, docker compose run all do). This was pointed out back in mid 2023 with a response that it was intentional.

While it doesn't make sense to invoke --interactive with Docker Compose given it's an implicit default, similar to how --tty has been replaced with --no-TTY (this really should accept all lowercase btw), the interactive flag does remain supported for legacy reasons (as noted at earlier linked ref).


Actual valid use-case however has been shown here where I advised a contributor about this hidden flag so that they could ensure a command was run non-interactively within a running container.

Not being able to do this would prevent the bash read -p command from working properly in a non-interactive context.

# Defaults: `--tty=false` + `--interactive=false`
docker exec container-name some-command

# Defaults: `--no-TTY=false` + `--interactive=true`
docker compose exec --no-TTY --interactive=false service-name some-command

Where some-command would call read -p to provide an interactive prompt otherwise, where:

  • Only --no-TTY: Prompt is hidden but otherwise remains interactive.
  • Only --interactive=false: Prompt appears and hangs as no input can actually be received.
  • Both opt-out flags used: No prompt shown and no stdin to receive input, proper non-interactive shell.
  • Neither opt-out present: Prompt appears and responds to input interactively. Blocks automation without workarounds.

Location

https://docs.docker.com/reference/cli/docker/compose/exec/

Suggestion

Document -i / --interactive is actually supported with a default of true and that it is also enabled by compose by default (similar to the equivalent docs of the --no-TTY option).

Activity

  1. ndeloof commented on Sep 4, 2025

    @ndeloof
    Contributor

    similar to how --tty has been replaced with --no-TTY

    this hasn't been replaced. There's been a distinct design decision in compose vs docker/cli as exec has been introduced in compose (2016). Nowadays we would require better alignment with the CLI for consistency.

    Actually, we introduced --tty later in compose to offer ability for user to select same flags for docker exec and docker compose exec, while it is a no-op for compose as a TTY is allocated by default.

  2. polarathene commented on Sep 4, 2025

    @polarathene
    ContributorAuthor

    Yeah I just realized afterwards that --tty=false also works despite lack of documented option. That helps for consistency when documenting the caveat to users of an image when calling the command and expecting non-interactive usage 👍

  3. thaJeztah commented on Sep 4, 2025

    @thaJeztah
    Member

    Ah, yes, these were added so that users familiar with docker exec -it ... would be able to do docker compose exec -it,;

    which would be a no-op because the defaults between compose and docker are reversed; I think we kept them hidden because the -T flag (disable TTY) already existed, and having both visible would probably be more confusing.

  4. thaJeztah commented on Sep 4, 2025

    @thaJeztah
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions