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

TTY Error running interactive docker on Bash on Windows #1588

Closed
waleedka opened this issue Jan 20, 2018 · 62 comments
Closed

TTY Error running interactive docker on Bash on Windows #1588

waleedka opened this issue Jan 20, 2018 · 62 comments

Comments

@waleedka
Copy link

A quick search online showed that a lot of people are frustrated about this issue. Basically, I'm trying to run Docker for Windows from the Bash on WSL (Windows Subsystem for Linux) on Windows 10 Creator Edition.

 docker.exe run -it hello-world

Returns this error:

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

The suggested solutions typically require installing external tools to work around the issue. I prefer not to prefix all my docker commands with winpty because then my scripts won't run on Linux boxes. And, actually, I prefer not to have to install winpty or any other tool just to work-around this issue. Can someone at Docker fix the issue at the root please?

Based on this thread, it seems this is a Docker issue. Quoting:

This is a docker.exe issue, I believe. It is not aware of the new console functionality and probably duplicates it to some degree. We saw similar problems on Win32-OpenSSH. Basically, when compiling docker.exe, they need to flip a few console flags up on the IO handles and disable their built-in terminal emulation code to allow the Windows console to take over processing.

Please look into it. You'd save your community a lot of frustration.

@jtrutwin-zz
Copy link

Um, No different running without the .exe, not sure why you expected that would work

jtrutwin@DESKTOP-PAK1BAG MINGW64 ~/git-projects/Hive (master)
$ docker run -it hello-world
the input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty'

Also running into this issue, hoping there's a fix down the road. Thanks.

@waqas-mehmood-pk
Copy link

Anybody find the solution to this issue? I am facing this one too.

@samoldenburg
Copy link

Any update on this issue?

@ray1007
Copy link

ray1007 commented Jul 19, 2018

I had the same problem. Below are my findings:

The command docker.exe run -it hello-world also failed in my WSL bash.
However I found the same command worked in both cmd and Powershell. (See below)
image
image
image

Perhaps one should not use docker.exe interactive/tty mode in WSL. I followed this guide to install docker client on WSL. And the command docker run -it hello-world executed with no error.
image

Still I haven't figured out why docker.exe works only on windows shells. I'd appreciate if someone could explain it! :)

Tzu-Ray

@docker-robott
Copy link
Collaborator

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale comment.
Stale issues will be closed after an additional 30d of inactivity.

Prevent issues from auto-closing with an /lifecycle frozen comment.

If this issue is safe to close now please do so.

Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows.
/lifecycle stale

@dekstroza
Copy link

Any news on this?

@tomasaschan
Copy link

/remove-lifecycle stale

I'm also wondering about this. Would be nice if this worked seamlessly in WSL!

@mrbarua
Copy link

mrbarua commented Dec 21, 2018

On git bash just type:
alias docker="winpty docker"
and tty will work

after starting the docker I mean when it will run
do a docker login from PowerShell (git-bash )and then use git-bash

then create docker conatainer
docker container run -it -p 80:80 nginx

@LarsWH
Copy link

LarsWH commented Jan 20, 2019

I was also seeing this problem, but after updating from version 1803 to 1809 it seems to have gone away (https://en.wikipedia.org/wiki/Windows_10_version_history).

@nngo
Copy link

nngo commented Feb 22, 2019

If your application does not need to send output text/etc to another application (e.g. for piping), then you don't need to run using the --tty or -t option to create a pseudo-terminal (i.e. for STDOUT). Additionally, if the application does not need to read from STDIN (then you can also omit the --interactive or -i option) e.g.

# this should still output to your console
docker run hello-world

In response to #1588 (comment)
When running the nginx web server, most of the time you don't need the -it (aka STDIIN via --interactive and STDOUT via --tty for the psuedo-tty options)

docker run -p 80:80 nginx

@FDiskas
Copy link

FDiskas commented Mar 2, 2019

I tried like so. Worked 😹
winpty docker run hello-world

@judgej
Copy link

judgej commented Apr 2, 2019

April 2019 - still seems to be a problem on Windows 10. docker cannot be run interactively without running it through winpty.

@Ruegen
Copy link

Ruegen commented May 11, 2019

same error here - I have to run it though winpty

@JoanComasFdz
Copy link

JoanComasFdz commented May 24, 2019

Just run into this error using zsh in Unbuntu in Hyper:

  • Windows 10 1709 Build 16299.1087
  • Docker Desktop Community 2.0.0.3 (31259) Build 8858db3 Engine 18.09.2.

When I run the command in cmd.exe it works.

@siochs
Copy link

siochs commented Jul 10, 2019

Just ommitting -it because it's not required by the container is not a solution:

$ docker run --rm -it debian:latest /bin/bash
the input device is not a TTY.  If you are using mintty, try prefixing the command with 'winpty'

Using winpty wrapper is not acceptable from my point of view, because it messes up with parsing the command line and with the environment variables:

$ winpty docker run --rm -it debian:latest /bin/bash
C:/Program Files/Docker/Docker/Resources/bin/docker.exe: Error response from daemon: OCI runtime create failed: container_linux.go:344: starting container process caused "exec: \"C:/Users/foo/AppData/Local/Programs/Git/usr/bin/bash.exe\": stat C:/Users/foo/AppData/Local/
Programs/Git/usr/bin/bash.exe: no such file or directory": unknown.

@LeeRuns
Copy link

LeeRuns commented Jul 10, 2019

Still does not work for me.

here is what i need to run from git bash on windows
~/$ winpty docker -it run simcompdocker /bin/bash stdin is not a tty

tried to drop the -i bc it is griping about input so i changed to this
~/$ winpty docker -t run simcompdocker /bin/bash stdin is not a tty

tried to drop all stdin stdout related work
~$ winpty docker run hello-world stdin is not a tty
setup is

  1. git-bash
  2. docker full windows install

@movielovers
Copy link

movielovers commented Jul 23, 2019

Just ommitting -it because it's not required by the container is not a solution:

$ docker run --rm -it debian:latest /bin/bash
the input device is not a TTY.  If you are using mintty, try prefixing the command with 'winpty'

Using winpty wrapper is not acceptable from my point of view, because it messes up with parsing the command line and with the environment variables:

$ winpty docker run --rm -it debian:latest /bin/bash
C:/Program Files/Docker/Docker/Resources/bin/docker.exe: Error response from daemon: OCI runtime create failed: container_linux.go:344: starting container process caused "exec: \"C:/Users/foo/AppData/Local/Programs/Git/usr/bin/bash.exe\": stat C:/Users/foo/AppData/Local/
Programs/Git/usr/bin/bash.exe: no such file or directory": unknown.

I didn't put the full path in for bash and it worked for me
winpty docker run --rm -it debian:latest bash

@LeeRuns
Copy link

LeeRuns commented Jul 23, 2019

bump

@sbkg0002
Copy link

Bump

@siochs
Copy link

siochs commented Jul 25, 2019

I didn't put the full path in for bash and it worked for me
winpty docker run --rm -it debian:latest bash

Okay, but this appears to me more like a workaround than a solution. Based on your hint, I found the following commands also working (which for the moment confuses me):
winpty docker run --rm -it debian:latest bin/bash
winpty docker run --rm -it debian:latest //bin//bash
winpty docker run --rm -it debian:latest //bin/bash
Also things like
winpty docker run --rm -it debian:latest //bin/bash -c "echo 'hello'"
work...

I don't know. Using winpty feels for me like installing a keyboard-driver-for-notepad.

@movielovers
Copy link

movielovers commented Jul 25, 2019

Still does not work for me.

here is what i need to run from git bash on windows
~/$ winpty docker -it run simcompdocker /bin/bash stdin is not a tty

tried to drop the -i bc it is griping about input so i changed to this
~/$ winpty docker -t run simcompdocker /bin/bash stdin is not a tty

tried to drop all stdin stdout related work
~$ winpty docker run hello-world stdin is not a tty
setup is

  1. git-bash
  2. docker full windows install

winpty docker -it run simcompdocker /bin/bash

this is incorrect so the -it goes after the run so
winpty docker run -it simcompdocker bash

Either way if even easy commands are failing like hello-world. Almost looks like something is not installed right.

$ winpty docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.

$ docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.

didnt even need winpty to run hello-world
I would say if its feasible maybe reinstall if you dont lose too much.

I also am using git-bash and windows docker full install, windows 10. But i am not expert here.

@dsebastien
Copy link

This is the alias I'm using, which seem to do the trick: docker(){(export MSYS_NO_PATHCONV=1; "winpty" "docker" "$@")}

@osoese
Copy link

osoese commented Sep 7, 2019

#!/bin/bash
docker run --name myshellbox --privileged -d shellbox
TEST_IT=$(docker exec myshellbox echo "Hello from container!")
echo ${TEST_IT}

this two step approach to get the output is what I use as a workaround when scripting to container

@muthu329024
Copy link

muthu329024 commented Oct 23, 2019

Is there any fix ?

issue:

Docker version: 19.03.1 (windows)

Invoking container from CMD: (works fine)

C:\Users\muthu>docker exec -it c31d1f693b74 /bin/bash
root@c31d1f693b74:/#

Same thing from git bash# (Not working)

$ docker exec -it c31d1f693b74 /bin/bash
the input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty'

60135734@EHL5CG72513QQ MINGW64 ~ (master)
$

Work around: As suggested by @siochs work's fine.

$ winpty docker exec -it c31d1f693b74 //bin//bash
root@c31d1f693b74:/#

ceefour added a commit to ceefour/frappe_docker that referenced this issue Feb 19, 2020
ceefour added a commit to ceefour/frappe_docker that referenced this issue Feb 19, 2020
@colthreepv
Copy link

as written by @siochs before:

Just ommitting -it because it's not required by the container is not a solution:

$ docker run --rm -it debian:latest /bin/bash
the input device is not a TTY.  If you are using mintty, try prefixing the command with 'winpty'

Using winpty wrapper is not acceptable from my point of view, because it messes up with parsing the command line and with the environment variables:

$ winpty docker run --rm -it debian:latest /bin/bash
C:/Program Files/Docker/Docker/Resources/bin/docker.exe: Error response from daemon: OCI runtime create failed: container_linux.go:344: starting container process caused "exec: \"C:/Users/foo/AppData/Local/Programs/Git/usr/bin/bash.exe\": stat C:/Users/foo/AppData/Local/
Programs/Git/usr/bin/bash.exe: no such file or directory": unknown.

the best workaround I could find is using a better winpty.
TLDR; download release from here and put it in a priority folder, ex: ~/bin/winpty.exe

$ where winpty
C:\Users\valerio\bin\winpty.exe
C:\Program Files\Git\usr\bin\winpty.exe

at this point the escaping will be correct ✔️

$ winpty echo "/data"
/data

instead of the dreaded 🤬

$ winpty echo "/data"
C:/Program Files/Git/data

For a longer explanation, refer to this issue on MSYS2-packages, and specifically this comment

This is such a LONG standing issue, by now I could apply for a paleontologist job.
My suggestion would be to approve a PR to document it on install.md or faqs.md

@universidadbackend
Copy link

This work for me on windows: winpty docker run -it ubuntu bash.

@gihanmu
Copy link

gihanmu commented Apr 11, 2020

alias docker="winpty docker"

worked for me

@jjqq2013
Copy link

jjqq2013 commented Apr 16, 2020

Just share a tip for Git Bash for Windows,

"Git Bash for Windows" ships with two bash program.

  • a GUI program "C:\Program Files\Git\git-bash.exe" (see right picture), called Git Bash, it does not provide tty.
  • a CUI program "C:\Program Files\Git\bin\bash.exe" (see left picture), it works perfect.

image

@ghost
Copy link

ghost commented Apr 16, 2020

@jjqq2013 the output says you to put the prefix winpty: winpty docker exec -it ubuntu: bash

@jjqq2013
Copy link

@joseaburt thank you for your kind reply. I just find that directly running "C:\Program Files\Git\bin\bash.exe" will have no such problem.

@grimimirg
Copy link

If this redundancy could be of any help:

As already somebody says above, inside .bashrc I used to write alias docker="winpty docker" like this:

image

then close and open git bash, and then:

image

@kendag
Copy link

kendag commented May 7, 2020

I had this issue and fixed it by updating mintty through the Cygwin installer:

mintty 3.1.4 (x86_64-pc-cygwin)

@inspiretk
Copy link

This worked for me:
In git bash windows 10, bind the word docker to "winpty docker"
alias docker="winpty docker"

Then ssh into a container like so:
docker exec -it containerName bash

I was using docker exec nginx-test /bin/bash and this doesnt work. Just remove the /bin/ and just use bash.

Summary: In git bash on windows 10. Run these commands:
alias docker="winpty docker"
docker exec -it containerName bash

Thanks everyone for helping!

@lbogdan
Copy link

lbogdan commented May 17, 2020

I was using docker exec nginx-test /bin/bash and this doesnt work.

@inspiretk That is because of MinGW's (which Git Bash uses) Posix path conversion. While only using bash works here (because /bin is in $PATH), if you really need an absolute path you can do either:

$ docker exec -it containerName //bin/bash

(notice the double //), or

$ MSYS_NO_PATHCONV=1 docker exec -it containerName /bin/bash

@LeeRuns
Copy link

LeeRuns commented Jun 24, 2020

i switched to new newest version of msys2 and started using mingw based on that (instead of the one that comes with git) and I am having much better success. Just an fyi for everyone interested in different method

@robertwt7
Copy link

This occurs on WSL as well...

alias aws='winpty docker run --rm -it amazon/aws-cli'

gave me samer error when running aws cli. I don't want to use git-bash :(

@Dhruvsahu9
Copy link

winpty docker run -it ubuntu bash

@Dhruvsahu9
Copy link

this comand worked for me,try using winpty

@bugslifesolutions
Copy link

Found a work-around (based on above winpty suggestion).

Scenario:

Run a bash script containing TTY (input/output) commands using mingw64/git bash.

Successful Command

winpty bash .//bin//package-link api-plugin-inventory-simple

Result:

\nUsing local package path /c/data/gitrepo2/reaction-development-platform/api-plugins/api-plugin-inventory-simple
If this is not correct, specify the correct path as the second argument.\n
Making directory /home/node/copied-packages/api-plugin-inventory-simple in 'api' container
Copying local api-plugin-inventory-simple package code into container path /home/node/copied-packages/api-plugin-inventory-simple ...
Linking package into API...

Unsuccessful Command (script as command)

$ winpty .//bin//package-link api-plugin-inventory-simple

Result:

winpty: error: cannot start 'C:/data/gitrepo2/reaction-development-platform/reaction/bin/package-link api-plugin-inventory-simple': %1 is not a valid Win32 application. (error 0xc1)

Unsuccessful Command (no winpty, directly invoke bash script)

$ ./bin/package-link api-plugin-inventory-simple

Result:

\nUsing local package path /c/data/gitrepo2/reaction-development-platform/api-plugins/api-plugin-inventory-simple
If this is not correct, specify the correct path as the second argument.\n
Making directory /home/node/copied-packages/api-plugin-inventory-simple in 'api' container
the input device is not a TTY.  If you are using mintty, try prefixing the command with 'winpty'

Root cause of TTY error:
docker-compose exec api sh -c "mkdir -p ${container_destination_path}"

Referenced Bash Script

#!/usr/bin/env bash

# Please Use Google Shell Style: https://google.github.io/styleguide/shell.xml

# ---- Start unofficial bash strict mode boilerplate
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -o errexit  # always exit on error
set -o errtrace # trap errors in functions as well
set -o pipefail # don't ignore exit codes when piping output
set -o posix    # more strict failures in subshells
# set -x          # enable debugging

IFS="$(printf "\n\t")"
# ---- End unofficial bash strict mode boilerplate

package_name=$1
package_path=$2
container_id="$(docker-compose ps -q api)"
container_copied_packages_path="/home/node/copied-packages"
container_destination_path="${container_copied_packages_path}/${package_name}"

if [[ -z "${package_path}" ]]; then
  package_name_without_org="${package_name/#@reactioncommerce\/}"
  package_path="../api-plugins/${package_name_without_org}"
  full_package_path="$(cd ${package_path} && pwd)"
  echo "\nUsing local package path ${full_package_path}"
  echo "If this is not correct, specify the correct path as the second argument.\n"
fi

echo "Making directory ${container_destination_path} in 'api' container"
docker-compose exec api sh -c "mkdir -p ${container_destination_path}"
echo "Copying local ${package_name} package code into container path ${container_destination_path} ..."
docker cp "${package_path}/." "${container_id}:${container_destination_path}"

# Then npm link into this project
echo "Linking package into API..."
docker-compose exec api sh -c "npm config set prefix /home/node/npm && cd /usr/local/src/app && npm link "${container_destination_path}""

# Fool nodemon into thinking something has changed so that it restarts.
# Touch first file found in /src with .js extension
echo "Restarting API..."
docker-compose exec api sh -c "touch -c $(ls ./src/*.js | head -n1)"

@bugslifesolutions
Copy link

@joseaburt thank you for your kind reply. I just find that directly running "C:\Program Files\Git\bin\bash.exe" will have no such problem.

I wish there was a way to highlight the simplest answer... @joseaburt you nailed it!
Thank you for sharing. Works like a charm.

Simple Solution

run <git for windows root>\bin\bash.exe

Successful Command

$ ./bin/package-link api-plugin-inventory-simple

Result

Using local package path /c/data/gitrepo2/reaction-development-platform/api-plugins/api-plugin-inventory-simple
If this is not correct, specify the correct path as the second argument.\n
Making directory /home/node/copied-packages/api-plugin-inventory-simple in 'api' container
Copying local api-plugin-inventory-simple package code into container path /home/node/copied-packages/api-plugin-inventory-simple ...

The process tree

image

@baerrach
Copy link

baerrach commented Sep 24, 2020

Combining a few answers as the docker tutorial commands:

docker exec e60043f6fcd3 cat /data.txt
docker run -it ubuntu ls /

Fail with the linux to windows name mangling and the tty emulation in git for windows bash.

.bashrc

# https://github.com/docker/toolbox/issues/673#issuecomment-355275054
# Workaround for Docker for Windows in Git Bash.
docker()
{
        (export MSYS_NO_PATHCONV=1; winpty "docker.exe" "$@")
}

# Workaround for tty issues and docker
# See:
# * https://github.com/msys2/MSYS2-packages/issues/411#issuecomment-372585320
# * https://github.com/docker/for-win/issues/1588 TTY Error running interactive docker on Bash on Windows
# * https://github.com/rprichard/winpty/issues/125 winpty not respecting non-path-munging env vars, or aliases
# Install newer version of WINPTY as per https://github.com/docker/for-win/issues/1588#issuecomment-594938988
export WINPTY_HOME=/C/winpty-0.4.3-msys2-2.7.0-x64
export PATH=${WINPTY_HOME}/bin:$PATH

@Dhruvsahu9
Copy link

Dhruvsahu9 commented Sep 24, 2020 via email

@docker-robott
Copy link
Collaborator

Issues go stale after 90 days of inactivity.
Mark the issue as fresh with /remove-lifecycle stale comment.
Stale issues will be closed after an additional 30 days of inactivity.

Prevent issues from auto-closing with an /lifecycle frozen comment.

If this issue is safe to close now please do so.

Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows.
/lifecycle stale

@georgettica
Copy link

This is still an issue, is the fix on the roadmap?

@shyaboi
Copy link

shyaboi commented Feb 3, 2021

I have experienced this error, similar to @ray1007
2021-02-02_19h21_18
Just like @ray1007 above, I just tried
docker run -it busybox sh
in gitbash and got this error
the input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty'
and as well, it works in my CMD and powershell fine, as you can see the containers running.

@docker-robott
Copy link
Collaborator

Closed issues are locked after 30 days of inactivity.
This helps our team focus on active issues.

If you have found a problem that seems similar to this, please open a new issue.

Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows.
/lifecycle locked

@docker docker locked and limited conversation to collaborators Mar 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests