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

Attach interactively to docker container #41

Closed
adaroobi opened this issue Apr 18, 2017 · 22 comments
Closed

Attach interactively to docker container #41

adaroobi opened this issue Apr 18, 2017 · 22 comments

Comments

@adaroobi
Copy link

As the title, Could not attach or exec using --interactive STDIN with error
the input device is not a TTY

@mintty
Copy link
Owner

mintty commented Apr 18, 2017

Note: an answer is available at the bottom of the issue.

Not the slightest idea what your actual use case is and what you want.
How should wsltty be related to Docker?

@mintty mintty added the invalid label Apr 18, 2017
@adaroobi
Copy link
Author

adaroobi commented Apr 19, 2017

Well, maybe an example could help.
Executing docker.exe run -it ubuntu bash

Expected:
To enter the container that's created and interact with with its prompt and keep the current stdin open.

Actual:

the input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty'

It can be executed only when omitting the -i flag but, this will no more keep the stdin open which reduces some usability.

@mintty
Copy link
Owner

mintty commented Apr 20, 2017

To start wsltty, you would have to somehow invoke wsltty, not just ubuntu bash.
Also, since mintty is a stand-alone Windows program, it does not use any stdin.
Where's the quoted output coming from, what would -i mean here... Your intent is obscure.
Unless you describe what you want clearly, and without assuming any knowledge about docker, I can only close the issue.

@adaroobi
Copy link
Author

I've started wsltty the way its described in the readme so its not a case of misuse but can be misunderstanding, an issue or something else, however I'll close this myself and reopen it when again when I am able to get an isolated example may help us both determine the intent.

Thanks.

@mamiu
Copy link

mamiu commented May 30, 2017

@mintty

Imagine following Situation:

  • Windows as development machine
  • Docker installed on Windows
  • Using docker through WSL
  • wsltty as terminal emulator

If I want to log into a docker container (which is a usual task during the use of docker. have a look here: https://askubuntu.com/a/507009) I'd type this command: docker.exe exec -i -t <container> /bin/bash.

But then, I'll get following error:
the input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty'

After prefixing 'winpty' the 'command not found' message appears.
winpty: command not found

Calling docker.exe exec -i -t <container> /bin/bash from the cmd (command prompt) I'm able to log into the docker container.

@mintty
Copy link
Owner

mintty commented May 30, 2017

winpty: command not found

So I suggest to install https://github.com/rprichard/winpty.
I agree it would be a good idea to integrate its functionality automatically, but that's a cygwin issue, not a mintty issue.
Actually, we may be having an additional problem layer here; I assume you invoke docker from WSL, within wsltty? In that case, actually, winpty should already be involved, in its incarnation as wslbridge. Don't know how to interpret the issue then; please clarify your workchain.

@mintty
Copy link
Owner

mintty commented May 30, 2017

There's also https://github.com/tiangolo/babun-docker
which may be helpful, provided you try to run docker from cygwin, which isn't clear from your description.

@adaroobi
Copy link
Author

@mintty I tried both suggestions before, but no successful result. I didn't get a time to dig further
and used cmd/ps instead...
Seems that I am not the only one who is experiencing the same symptoms.

@mamiu
Copy link

mamiu commented May 30, 2017

I don't use cygwin. I just installed WSL and instead of using the old fashioned cmd for the ubuntu bash I also installed wsltty, which btw is awesome!
I used it for a while and everything worked fine. Than, somebody came up with docker for windows. So I installed docker for windows to improve my development workflow, but docker doesn't run smoothly within wsltty. First I had some codepage issues, which I resolved with chcp.com 932. After that everything else was running frictionless again. But logging into a docker container is the only thing, that doesn't work so far.

I think more cannot be said. If you still have questions, please ask! :)

@mintty
Copy link
Owner

mintty commented May 30, 2017

Your codepage issue is probably an instance of mintty/mintty#376 and the I/O interworking one of mintty/mintty#56, both not really being mintty issues.

So you invoke Windows docker from WSL (inside wsltty), right?
I wasn't aware this is possible at all.
This seems to be the reverse interworking case of what wslbridge accomplishes within wsltty;
@rprichard, any idea about the issue?

@rprichard
Copy link

FWIW: wslbridge and winpty aren't that related, though I wrote both. wslbridge is more robust.

  • wslbridge: bridges between two Unix ptys

  • winpty: connects a Windows console to a Cygwin/MSYS pty

WSL can run console programs, but in my limited testing, it didn't work very well. A WSL pty was regarded as a FILE_TYPE_CHAR device, so isatty returned true for C stdio handles. Ctrl-C didn't work. I tried a few console-specific APIs, and they didn't work with the WSL pty handles (understandably). A WSL pty only generates VT/100 input, so control/navigation keys didn't work with the programs I tried (cmd, powershell, python3).

I looked into Docker/winpty integration a while ago. IIRC, Docker had a client program that didn't use Cygwin/MSYS, and it worked something like a Windows SSH client -- if its stdio were connected to a console, then it'd create a pty in the Linux VM and handle escape sequences, and otherwise, it would just copy bytes between the Linux VM and the Windows STDIN/STDOUT/STDERR file handles. If you tried to run Docker in mintty with a Cygwin pty, then it'd kinda work, except that it wouldn't create a Linux pty?

wslbridge has a Cygwin/MSYS program frontend that connects to a WSL pty, but it wouldn't be that hard to flip it around. You could use inverted-wslbridge to connect from wsltty to a Cygwin pty, then run winpty inside that. That's 4 adapters to the Linux VM, though:

  • mintty.exe (Cygwin pty)
    • wslbridge.exe (Cygwin pty -> WSL pty)
      • inverted-wslbridge.exe (WSL pty -> Cygwin pty)
        • winpty.exe (Cygwin pty -> console)
          • docker.exe? (console -> Linux pty)

Maybe it'd be OK -- wslbridge mostly just adds latency. winpty.exe and docker.exe would cause most of the trouble. inverted-wslbridge would be a WSL program that runs a Cygwin/MSYS inverted-wslbridge-backend.exe program, and you'd also need a winpty.exe built for the same Cygwin/MSYS environment.

A WSL winpty adapter might be possible. It would be easier if WSL could access Win32 named pipes. (Maybe it can, somehow?) Maybe winpty could use sockets instead of named pipes.

It could also make sense to have a WSL docker adapter (i.e. WSL pty -> Linux pty). I'm wondering what's happening in the Docker VM when docker.exe connects.

@raupie
Copy link

raupie commented Nov 1, 2017

I have the same exact issue.

Installed Docker for Windows. Enabled WSL. Exposed the TCP port. Created windows Firewall rule.

Can run docker.exe commands however exec fails with the input device is not a TTY. If you are using mintty, try prefixing the command with winpty.

I installed wsltty, ran it from the context menu, still getting the same message. Am I missing something?

@mintty
Copy link
Owner

mintty commented Nov 1, 2017

This issue is related to subtle mutual interaction between pty-based and console-based programs. See rprichard's comment above for some technical details.
It is not quite clear from your description what exactly fails (exec where) and what/how it does not fail.
However, that wouldn't help as long as there is no inverted-wslbridge. Also note that this is not a mintty-specific issue, you might cross-check with xterm.

@mintty
Copy link
Owner

mintty commented Nov 2, 2017

Does docker have an interactive mode? (A kind of shell?)
In that case, mintty could perhaps run docker directly, probably with winpty. Not in the same terminal as WSL, though.
Maybe WSLtty could bundle winpty anyway, so you could also launch e.g. a cmd.exe session in parallel.
@rprichard, any comments?

@mintty mintty reopened this Nov 2, 2017
@rprichard
Copy link

It could make sense to package winpty with wsltty, I suppose. You'd need a special shortcut that launches mintty with cmd using winpty. Needing to start a new terminal window to connect to a Docker instance strikes me as disruptive to one's workflow, but maybe it's OK?

It's unfortunate that the Docker instance and mintty both use VT100 I/O, but we have to bridge between the two with console I/O, a translation process that's lossy and adds latency.

@mintty
Copy link
Owner

mintty commented Nov 3, 2017

Not really belonging here, but: I noticed again, on this occasion, that with winpty cmd.exe ^C does not work (which is better than quitting cmd.exe, of course). Any chance to fix that?

@rprichard
Copy link

winpty's Ctrl-C problem is tracked here, rprichard/winpty#116. It's hard to fix.

@kevin-wang-cy
Copy link

kevin-wang-cy commented Nov 7, 2017

I got same issue when I try docker -it command in the bash on Ubuntu on Windows (WSL) , it report below errors:
{quote}
the input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty
{quote}

Hope it can be fixed soon

@mintty
Copy link
Owner

mintty commented Nov 7, 2017

What {quote}?
And the technical conditions for a "fix" have been discussed here; there is currently no fix in sight. It's a multiple-interworking issue.

@caot
Copy link

caot commented Feb 20, 2018

Here is how to make it work:

  1. build and install https://github.com/rprichard/winpty
  2. then run as the follows:
    winpty docker run -ti --rm image_REPOSITORY_name:latest sh

@whereisaaron
Copy link

whereisaaron commented Oct 4, 2018

I had this problem with the original WSL on Windows. I couldn't work out how to get rid of mintty and winpty was not installed, and not desirable anyway. Installing the new from Windows store version fixed the probably and the shell worked as a tty. I had to reinstall, but this is much better.

PS C:\> wslconfig.exe /list
Windows Subsystem for Linux Distributions:
Legacy (Default)  <---- tty problem
Ubuntu  <---- works! :)

P.S. I fooled myself at one point by inadvertently running docker.exe from WSL rather than docker (due to an alias). Running docker.exe causes the 'mintty/wintty' error.

@mintty
Copy link
Owner

mintty commented Dec 17, 2019

Released 3.1.0.2, bundling binary installer with cygwin 3.1.0, with ConPTY support.
Please recheck.

@mintty mintty closed this as completed Dec 17, 2019
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

8 participants