docker error on windows : the input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty' [duplicate] - windows

This question already has answers here:
Error "The input device is not a TTY"
(16 answers)
Closed 2 years ago.
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.

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

If you are using Git Bash you can try like this
winpty docker run -it ubuntu

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

This works for me.
I am using git bash on windows
winpty docker-compose exec app ls -l

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

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.

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:
That launches this …
… you can run your docker commands there without getting that error or running winpty.

The problem is with gitbash however with the powershell it is working fine ..

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:
Try running the command from your docker terminal. (gives you privilege).
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).

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/

Got this error for running docker-compose exec workspace bash
So just prefix with winpty winpty docker-compose exec workspace bash

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.

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

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

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.

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.

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

Related

Docker keeps complaining about the input device is not TTY

I'm using Windows-10 and using GitBash entering in the command
$ docker run -ti ubuntu:latest bash
And it gives me this error message
"the input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty'"
And so I placed in this command to switch to winpty
$ winpty docker.exe run -it --rm ubuntu:14.04 /bin/bash
And it still doesn't work. I know my ports are running correctly, and I installed ubuntu correctly.
At windows 10 and git bash this works for me:
winpty docker exec -it "CONTAINTER ID" sh

GitLab ci cannot start bash in container

Good day!
I am using powershell shell executor for gitlab runner. For the test I need to run bash in my php-fpm container but I get a strange error
docker exec -it phpfpm bash
error:
the input device is not a TTY. If you are using mintty, try prefixing the command with winpty
also i tried to run command with winpty prefix
winpty docker exec -it phpfpm bash
or
winpty -Xallow-non-tty docker exec -it phpfpm bash
but "winpty" is not internal or external
command, executable program, or batch file.
i installed git with standard windown shell option instead of MTY
also i tried to install winpty but it didn't work. Are there any options to solve this problem or what could be the problem?

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

I try to run the following Docker command in git bash shell.
docker exec -it service /bin/bash
but I get the following error
the input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty'
When I try to run the command with winpty as follows
winpty docker exec -it service /bin/bash
The git bash shell just prompts for the next command, but mess up with rendering the text on the screen. How do I properly attach interactive shell on the Docker container on git bash?
I can run the command in Docker Quickstart Terminal, but the problem is the terminal output history is very limited (old output is lost when new ouput is printed). Alternatively, how do I extend the output history size to unlimited scrolling on the Docker Quickstart Terminal?
try using:
winpty -Xallow-non-tty docker exec -it service /bin/bash
it worked for me.
another alternative (if using Docker w/ windows 10).
(1)
If Git is not already installed: install it.
(2)
from windows 10 search (i.e., lower lefthand corner: "Type here to search"), type in "Git"
(3)
click the "Git CMD (Deprecated) App"
(4)
use the shell that is invoked. It seems the "-it" switch is supported...
e.g.,
docker exec -it db2 /bin/bash

Automatically enter only running docker container

In the cloud, I have multiple instances, each running a container with a different random name, e.g.:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5dc97950d924 aws_beanstalk/my-app:latest "/bin/sh -c 'python 3 hours ago Up 3 hours 80/tcp, 5000/tcp, 8080/tcp jolly_galileo
To enter them, I type:
sudo docker exec -it jolly_galileo /bin/bash
Is there a command or can you write a bash script to automatically execute the exec to enter the correct container?
"the correct container"?
To determine what is the "correct" container, your bash script would still need either the id or the name of that container.
For example, I have a function in my .bashrc:
deb() { docker exec -u git -it $1 bash; }
That way, I would type:
deb jolly_galileo
(it uses the account git, but you don't have to)
Here's my final solution. It edits the instance's .bashrc if it hasn't been edited yet, prints out docker ps, defines the dock function, and enters the container. A user can then type "exit" if they want to access the raw instances, and "exit" again to quit ssh.
commands:
bashrc:
command: if ! grep -Fxq "sudo docker ps" /home/ec2-user/.bashrc; then echo -e "dock() { sudo docker exec -it $(sudo docker ps -lq) bash; } \nsudo docker ps\ndock" >> /home/ec2-user/.bashrc; fi
As VonC indicated, usually you have to make some shell scripting of your own if you find yourself doing something repetitive. I made a tool myself here which works if you have Bash 4+.
Install
wget -qO- https://raw.githubusercontent.com/Pithikos/dockerint/master/docker_autoenter >> ~/.bashrc
Then you can enter a container by simply typing the first letters of the container.
$> docker ps
CONTAINER ID IMAGE ..
807b1e7eab7e ubuntu ..
18e953015fa9 ubuntu ..
19bd96389d54 ubuntu ..
$> 18
root#18e953015fa9:/#
This works by taking advantage of the function command_not_found_handle introduced in Bash 4. If a command is not found, the script will try and see if what you typed is a container and if it is, it will run docker exec <container> bash.

Docker. How to get bash\ssh inside runned container (run -d)?

I want to ssh or bash into runned docker container. Please, see example:
$ sudo docker run -d webserver
webserver is clean image from ubuntu:14.04
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
665b4a1e17b6 webserver:latest /bin/bash ... ... 22/tcp, 80/tcp loving_heisenberg
now I want to get something like this (go into runned container):
$ sudo docker run -t -i webserver (or maybe 665b4a1e17b6 instead)
$ root#665b4a1e17b6:/#
Previously I used Vagrant so I want to get behavior similar to vagrant ssh. Please, could anyone help me?
After the release of Docker version 1.3, the correct way to get a shell or other process on a running container is using the docker exec command. For example, you would run the following to get a shell on a running container:
docker exec -it myContainer /bin/bash
You can find more information in the documentation.
The answer is docker attach command.
For information see: https://askubuntu.com/a/507009/159189

Resources