Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] exec/run switch to enable guessing when to allocate a TTY #3997

Open
jedwards1211 opened this issue Feb 1, 2023 · 1 comment

Comments

@jedwards1211
Copy link

jedwards1211 commented Feb 1, 2023

Description

Companion issue to docker/compose#10227 since their behavior should be consistent.

I believe in common cases docker exec and docker run could correctly guess when stdin is a TTY and behave accordingly.

I often use psql in the postgres docker container. If I want to start an interactive terminal, I have to use -it:

docker exec -it db  psql -U postgres

If I want to pipe a command to it, I have to use -i:

echo 'SELECT 1;' | docker exec -i db psql -U postgres

I've made numerous mistakes forgetting the correct flags in scripts, especially since different flags work for docker compose exec:

docker compose exec db  psql -U postgres
echo 'SELECT 1;' | docker compose exec -T db psql -U postgres

docker compose used to try to guess when to allocate a TTY, but they gave up on that because of some obscure bug: docker/compose#9035.

But a switch to enable TTY detection would be good. I'd rather have a switch to tell exec/run to guess when to allocate a TTY (in compose and base docker cli) that futz with it manually.

@thaJeztah
Copy link
Member

It's a tricky one. For compose, the situation was mostly in reverse; it would always use a TTY, unless disabled; this caused issues in cases where no TTY should be used, and because of that detection was needed when it could not be used (so needed to be disabled).

Detecting "when to not" attach a TTY (in the compose case) may be slightly easier (don't attach one when piping), but I'm not sure if the "reverse" is easy to do (even more so: without it being a breaking change). There's many scenarios where docker run is used and no tty should be attached (even without piping output).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants