docker / cli

The Docker CLI
Apache License 2.0
4.97k stars 1.94k forks source link

[Feature Request] Allow sending some input through TTY when attaching #1383

Open jazzdelightsme opened 6 years ago

jazzdelightsme commented 6 years ago

If you try to pipe some input when attaching to a container that has a TTY, you are told it can't work:

PS C:\src\thing> "`n" | docker attach mycontainer
the input device is not a TTY.  If you are using mintty, try prefixing the command with 'winpty'

This makes sense, because a string is not a terminal interface (TTY).

However, it would be really handy to be able to send some input through the actual TTY once it is hooked up.

The use case I am considering is a container that is running an interactive shell (with TTY). When you attach to such a container, assuming the shell is just sitting there idle, you don't see any indication that you're hooked up--no prompt or anything. The documentation even spells this out:

"This can appear as if the attach command is hung when in fact the process may simply not be interacting with the terminal at that time."

It would be really handy to be able to ask attach, hey, once you have your hijackedIOStreamer hooked up, could you please send along this text through it? This would allow, for example, sending a newline to an otherwise idle shell, triggering a new prompt to be output, without requiring the user to know that they need to bang on the enter key a few times until they get a prompt.

jazzdelightsme commented 6 years ago

Suppose this feature were implemented with a --tty-input switch. That would allow writing the following function:

function Enter-ContainerShell( $containerName )
{
    $lf = "'n"
    # Send LF to "tickle" container shell so we see a prompt:
    docker attach $containerName --tty-input $lf
}

Mockup:

PS C:\src\thing> Enter-ContainerShell thirsty_wright

PS />