126

After I run this

docker run --rm -v "/c/users/vipul rao/documents/github/wappalyzer:/opt/wappalyzer" -it wappalyzer/dev

I am getting the following error

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

What should I use here? I am running Docker on Windows 8 in MINGW64.

simhumileco
  • 31,877
  • 16
  • 137
  • 115
Vipul Rao
  • 1,495
  • 2
  • 10
  • 15

17 Answers17

147

As suggested by the error message you obtain, you should try to use winpty (which is installed by default with Git-Bash) and thus run:

winpty docker run --rm -v "/c/users/vipul rao/documents/github/wappalyzer:/opt/wappalyzer" -it wappalyzer/dev

If this works, you may want to set a Bash alias to avoid manually prepending winpty all the time:

echo "alias docker='winpty docker'" >> ~/.bashrc

or

echo "alias docker='winpty docker'" >> ~/.bash_profile
ErikMD
  • 13,377
  • 3
  • 35
  • 71
40

If you are using Git Bash you can try like this

winpty docker run -it ubuntu
w3outlook
  • 823
  • 6
  • 16
36

This problem occurs when running with -it option using bash terminal on windows. You can use Powershell to resolve this issue.

yamenk
  • 46,736
  • 10
  • 93
  • 87
  • 1
    Can add the explanation as to why? – Tarun Lalwani Feb 05 '18 at 13:16
  • This is the error i am getting after using powershell `$ docker run --rm -v "/c/users/vipul rao/documents/github/wappalyzer:/opt/wappalyzer" -it wappalyzer/dev C:\Program Files\Docker Toolbox\docker.exe: error during connect: Post http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.35/containers/create: open //./pipe/docker_engine: The system cannot find the file specified. In the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running. See 'C:\Program Files\Docker Toolbox\docker.exe run --help'.` – Vipul Rao Feb 06 '18 at 04:15
  • 1
    You need to connect the shell to the docker deamon by setting the env variables from the command `docker-machine env default`. You can also use the Docker quick start terminal which is connected to the docker deamon. – yamenk Feb 06 '18 at 08:30
  • 1
    The Powershell fixed my problem – Wesley Abbenhuis Aug 07 '18 at 13:49
  • I'm using Powershell and still getting this error. I don't even know what winpty, mintty or git-bash is. I don't use git. Removing `-it` doesn't solve this. – gargoylebident Apr 21 '22 at 05:43
26

This works for me. I am using git bash on windows

winpty docker-compose exec app ls -l
Emeka Mbah
  • 16,745
  • 10
  • 77
  • 96
16

Remove -it from the command. If you want to keep it interactive then keep -i

Harsh
  • 460
  • 5
  • 9
  • 6
    OK but this does not solve the problem, it only avoids it :) – ErikMD Apr 29 '18 at 20:09
  • It doesn't even avoid it. I removed `-it` but I'm still getting the error, running natively in Powershell, no wintty, no mintty not Git-Bash anywhere in the system (idek what those things are). – gargoylebident Apr 21 '22 at 05:47
12

Don't use alias docker="winpty docker". It solves your problem but break pipes.

$ winpty docker run -ti ubuntu
root@e85cff7d1670:/# exit

$ wintpy docker run ubuntu bash HELLO 
HELLO

$ wintpy docker run ubuntu bash HELLO | cat
stdout is not a tty

Copy this to your .bashrc. This script uses winpty docker only if -ti is used.

function docker(){
  for param; do if [[ "$param" == "-ti" ]] || [[ "$param" == "-it" ]]; then 
    winpty docker "$@"; return
  fi; done; 
  command docker "$@"
}

docker run -ti ubuntu becomes winpty docker run -ti ubuntu avoids error: the input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty'"

docker run ubuntu echo "what's up" | cat becomes command docker run echo "what'up" | cat avoids error: stdout is not a tty

The script only looks if there is a '-it' parameter without checking if it is inside a 'docker run' sentence... but it does the trick for my uses.

cesarpino
  • 123
  • 1
  • 5
  • 1
    Upvoted for mentioning the pipe problem. Checking only for arg `-it` or `-ti` (anywhere) is probably enough for most interactive usage, but checking whether stdout is a tty (`[ -t 1 ]`) would be cleaner. – EndlosSchleife Jul 24 '20 at 14:47
  • thanks! this worked while the alias did not – Reine Baudache Apr 26 '22 at 09:40
8

The problem happens when you use gitbash however you can open a CMD or Powershell and it works fine

enter image description here

Mauricio Gracia Gutierrez
  • 10,288
  • 6
  • 68
  • 99
Naveen Yadav
  • 91
  • 1
  • 1
5

Did you start "Docker Quickstart Terminal"? I was trying to run

$ docker run -i -t redcricket/react-tutorial:latest /bin/bash

on windows from a Cygwin bash shell and got the same error:

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

Then I remembered that when I installed docker on my windows 10 system something called "Docker Quickstart Terminal" got installed. You need to start that first from that dumb windows 'Type here to search' thing on the task bar:

enter image description here

That launches this …

enter image description here

… you can run your docker commands there without getting that error or running winpty.

Red Cricket
  • 9,762
  • 21
  • 81
  • 166
4

Just add 'winpty' in start of your cmd ,Try below:

$ winpty docker.exe run --rm -v "/c/users/vipul rao/documents/github/wappalyzer:/opt/wappalyzer" -it wappalyzer/dev

Why this happens? More details here: http://willi.am/blog/2016/08/08/docker-for-windows-interactive-sessions-in-mintty-git-bash/

Salman Saleem
  • 223
  • 2
  • 9
4

Happened to me. From Git Bash, on Windows 8 running Docker Toolbox. There are two things happening. From git bash, we do not seem to have complete escalated privilege to the docker daemon (even though i'm running git bash with administrative privileges). Thus:

  1. Try running the command from your docker terminal. (gives you privilege).

  2. To compensate for errors from Window's folder naming formats, don't forget to quote the path.. (to escape spaces and/or capitalization errors) say

From:

docker run -v $(pwd):/data image_ref

To:

docker run -v "$(pwd):/data" image_ref

(notice the enclosing quotes in the latter around $(pwd):/data).

AlBlue
  • 23,254
  • 14
  • 71
  • 91
xxandra
  • 41
  • 1
2

Got this error for running docker-compose exec workspace bash

So just prefix with winpty winpty docker-compose exec workspace bash

Jason Spick
  • 6,028
  • 13
  • 40
  • 59
1

It may be that you're not running your commands within the Docker terminal. If you don't, you may not be properly connected to the Docker daemon and won't be able to interact correctly.

Make sure you're running commands in the actual Docker Terminal.

1

For those using WSL and running Docker for windows inside of cmder or conemu I would recommend to not to use Docker which is installed on windows in 'Program Files' but instead install Docker inside WSL on ubuntu/linux. Do remember though that you can't run Docker itself from within WSL, you must connect to Docker running on windows from the linux Docker client installed in WSL.

To install Docker on WSL

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install docker-ce

Your options for running actual Docker commands are to either: Connect to Docker using the switch -H

docker -H localhost:2375 run -it -v /mnt/c/code:/var/app -w "/var/app" centos:7

Or set the environment variable docker_host

export DOCKER_HOST=tcp://localhost:2375

Either way you are now be able to interactively connect to a running Docker container

Damo
  • 5,698
  • 3
  • 37
  • 55
  • Also remember to remove any alias to the windows docker from within WSL. you can see what docker will be executed by running ```which docker``` – Damo Jul 31 '19 at 15:17
0

you can try with Cmder tool it will work. Its not working with Gitbash

Narendra
  • 127
  • 3
  • 11
0

In addition to above mentioned solutions. In case you are getting this error for docker attach

example: docker attach alpine1

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

Solution: Adding winpty before docker command i.e. winpty docker attach should work.

example: winpty docker attach alpine1

Note: I was getting this error while using base on windows and this solution worked for me.

Balpreet Patil
  • 1,644
  • 2
  • 16
  • 16
0

I had the same error when trying to run the docker-compose exec command. In the help documentation docker-compose exec --help it shows how you can disable the pseudo-tty allocation by adding -T to your command options in the following way:

docker-compose exec -T

From the help documentation:

-T Disable pseudo-tty allocation. By default docker-compose exec allocates a TTY.

-1

If you are using gitbash the problem is when setting the terminal emulator for for using with Git bash.setting the emurator

Instead you can change the emulator to the first options or use the
winpty command before your docker run command