Jay Taylor's notes
back to listing indexdocker - Error "The input device is not a TTY" - Stack Overflow
[web search]-
18
- +1408
QuestionsTagsUsersCollectives- Explore Collectives
- Find a Job
JobsCompaniesI am running the following command from my
Jenkinsfile
. However, I get the error "The input device is not a TTY".docker run -v $PWD:/foobar -it cloudfoundry/cflinuxfs2 /foobar/script.sh
Is there a way to run the script from the
Jenkinsfile
without doing interactive mode?I basically have a file called
script.sh
that I would like to run inside the Docker container.For *nix, it looks like there is no solution here. 'docker exec -i' doesn't work, nor does '-t'.– rjurneyJul 24 '18 at 16:32@rjurney Did you ever find a solution for docker exec ? I to have tried -i and -t with no success. docker exec -it mycontainer bash certbot --apache -d www.website.com --email *********@gmail.com --agree-tos -n– HutchNov 1 '19 at 8:41Remove the
-it
from your cli to make it non interactive and remove the TTY. If you don't need either, e.g. running your command inside of a Jenkins or cron script, you should do this.Or you can change it to
-i
if you have input piped into the docker command that doesn't come from a TTY. If you have something likexyz | docker ...
ordocker ... <input
in your command line, do this.Or you can change it to
-t
if you want TTY support but don't have it available on the input device. Do this for apps that check for a TTY to enable color formatting of the output in your logs, or for when you later attach to the container with a proper terminal.Or if you need an interactive terminal and aren't running in a terminal on Linux or MacOS, use a different command line interface. PowerShell is reported to include this support on Windows.
What is a TTY? It's a terminal interface that supports escape sequences, moving the cursor around, etc, that comes from the old days of dumb terminals attached to mainframes. Today it is provided by the Linux command terminals and ssh interfaces. See the wikipedia article for more details.
To see the difference of running a container with and without a TTY, run a container without one:
docker run --rm -i ubuntu bash
. From inside that container, install vim withapt-get update; apt-get install vim
. Note the lack of a prompt. When running vim against a file, try to move the cursor around within the file.answered Mar 29 '17 at 16:31I'm using this command in conjunction withmysql -p
without specifiying a password. When just adding-i
the password prompt never appears. With just adding-t
the prompt appears but it seems to not read the input (which is printed literally instead of being hidden by the prompt) at all, not even when hitting return; only ctrl-c can end it. Is it somehow possible to use the mysql client with docker that way?– ohcibiJul 22 '18 at 12:21Thank you for this! For docker-compose users, I wanted to add that I had a similar command to run - I wanted to delete redis keys based on a pattern - and was able to do so with thedocker-compose exec -T
command. From the man page fordocker-compose exec
:Disable pseudo-tty allocation. By default docker-compose exec allocates a TTY.
– Yacine BJul 21 '20 at 21:13It's not exactly what you are asking, but:
For
docker-compose exec
use-T
flag!The -T key would help people who are using docker-compose exec! (It disable pseudo-tty allocation)
For example:
docker-compose -f /srv/backend_bigdata/local.yml exec -T postgres backup
or
docker-compose exec -T mysql mysql -uuser_name -ppassword database_name < dir/to/db_backup.sql
answered Aug 19 '19 at 23:44Just what I needed too. According to the help: -T Disable pseudo-tty allocation. By defaultdocker-compose exec
allocates a TTY.– T.S.Jan 26 '20 at 16:26with MySQL database running on mysql virtual machine (with the suggested -T above):docker-compose exec -T mysql mysql -uuser_name -ppassword database_name < dir/to/db_backup.sql
Jun 24 at 17:29For those who struggle with this error and git bash on Windows, just use PowerShell where
-it
works perfectly.answered Aug 24 '17 at 19:19This does not answer the question. The question is about docker in Jenkins, not git bash on Windows.– user1544337Feb 12 '18 at 16:40Well. true, and it was never intended to. The question pops up in google when you search for this specific error message. I figured, better to have the answer somewhere than not to have it at all. Clearly some people found it useful :) Feb 12 '18 at 19:11The problem with Powershell as TTY for shell operations is that it does not properly pass the arrow keys, like the up arrow for cycling command history. Works great other than that shortcoming. Feb 28 '18 at 22:49If you want to continue to use Git Bash, see this answer on another question or the winpty answer below– tessafyiJun 18 '18 at 20:49If you are (like me) using git bash on windows, you just need to put
winpty
before your 'docker line' :
winpty docker exec -it some_cassandra bash
answered May 23 '18 at 8:52Did you try before asking ? I think it comes with Git (mine is inside .../Git/usr/bin)– Gremi64Dec 3 '18 at 10:23I believe you need to be in a TTY for docker to be able to allocate a TTY (the
-t
option). Jenkins executes its jobs not in a TTY.Having said that, the script you are running within Jenkins you may also want to run locally. In that case it can be really convenient to have a TTY allocated so you can send signals like ctrl+c when running it locally.
To fix this make your script optionally use the
-t
option, like so:test -t 1 && USE_TTY="-t" docker run ${USE_TTY} ...
answered Jan 12 '18 at 16:15This error happen to me when runningdocker run…
command form a makefile task triggered by a git hook Oct 17 '18 at 18:03this should be the accepted answer. it actually adresses the problem in a universally applicable manner– sgohlMay 6 '20 at 16:12when using 'git bash',
1) I execute the command:
docker exec -it 726fe4999627 /bin/bash
I have the error:
the input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty'
2) then, I execute the command:
winpty docker exec -it 726fe4999627 /bin/bash
I have another error:
OCI runtime exec failed: exec failed: container_linux.go:344: starting container process caused "exec: \"D:/Git/usr/bin/ bash.exe\": stat D:/Git/usr/bin/bash.exe: no such file or directory": unknown
3) third, I execute the:
winpty docker exec -it 726fe4999627 bash
it worked.
when I using 'powershell', all worked well.
answered Jul 7 '19 at 13:55Banged my head against the wall, too, for a couple hours with these issues using bash. Switched to Powershell and all works now! Oct 22 '19 at 18:23(2) fails becausewinpty
converts unix-filepath-like arguments into Windows-speak. To see this clearly:winpty echo "/foo/bar"
printsC:/Program Files/Git/foo/bar
. Mar 10 at 17:06Using docker-compose exec -T fixed the problem for me via Jenkins
docker-compose exec -T containerName php script.php
answered Nov 10 '20 at 22:54if using windows, try with cmd , for me it works. check if docker is started.
In Jenkins, I'm using docker-compose exec -T
eg:-
docker-compose exec -T app php artisan migrate
I know this is not directly answering the question at hand but for anyone that comes upon this question who is using WSL running Docker for windows and cmder or conemu.
The trick is not to use Docker which is installed on windows at /mnt/c/Program Files/Docker/Docker/resources/bin/docker.exe but rather to install the ubuntu/linux Docker. It's worth pointing out that you can't run Docker itself from within WSL but you can connect to Docker for windows from the linux Docker client.
Install Docker on Linux
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common 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
Connect to Docker for windows on the port 2375 which needs to be enabled from the settings in docker for windows.
docker -H localhost:2375 run -it -v /mnt/c/code:/var/app -w "/var/app" centos:7
Or set the docker_host variable which will allow you to omit the -H switch
export DOCKER_HOST=tcp://localhost:2375
You should now be able to connect interactively with a tty terminal session.
For those using Pyinvoke see this documentation which I'll syndicate here in case the link dies:
99% of the time, adding pty=True to your run call will make things work as you were expecting. Read on for why this is (and why pty=True is not the default).
Command-line programs often change behavior depending on whether a controlling terminal is present; a common example is the use or disuse of colored output. When the recipient of your output is a human at a terminal, you may want to use color, tailor line length to match terminal width, etc.
Conversely, when your output is being sent to another program (shell pipe, CI server, file, etc) color escape codes and other terminal-specific behaviors can result in unwanted garbage.
Invoke’s use cases span both of the above - sometimes you only want data displayed directly, sometimes you only want to capture it as a string; often you want both. Because of this, there is no “correct” default behavior re: use of a pseudo-terminal - some large chunk of use cases will be inconvenienced either way.
For use cases which don’t care, direct invocation without a pseudo-terminal is faster & cleaner, so it is the default.
winpty works as long as you don't specify volumes to be mounted such as ".:/mountpoint" or "${pwd}:/mountpoint"
The best workaround I have found is to use the git-bash plugin inside Visual Code Studio and use the terminal to start and stop containers or docker-compose.
My Jenkins pipeline step shown below failed with the same error.
steps { echo 'Building ...' sh 'sh ./Tools/build.sh' }
In my "build.sh" script file "docker run" command output this error when it was executed by Jenkins job. However it was working OK when the script ran in the shell terminal.The error happened because of -t option passed to docker run command that as I know tries to allocate terminal and fails if there is no terminal to allocate.
In my case I have changed the script to pass -t option only if a terminal could be detected. Here is the code after changes :
DOCKER_RUN_OPTIONS="-i --rm" # Only allocate tty if we detect one if [ -t 0 ] && [ -t 1 ]; then DOCKER_RUN_OPTIONS="$DOCKER_RUN_OPTIONS -t" fi docker run $DOCKER_RUN_OPTIONS --name my-container-name my-image-tag
This post is hidden. It was deleted 10 months ago by the post author.My suggestion is to change your logic and use shell substitutions instead:
docker exec -it $(your | long | pipeline |) <whatever>
answered Nov 27 '20 at 11:17This doesn't make any sense; it would runyour | long | pipeline
in the current shell, and pass the output as an argument todocker exec
– tripleeeNov 27 '20 at 11:19Yes, you are right, I put this answer in the wrong question . Anyway this makes sense when you need docker to use the result of pipe and than use the current terminal. As in ``` my | long | pipeline | docker exec --it container name resultofthepipe``` Nov 28 '20 at 20:18Your Answer
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Not the answer you're looking for? Browse other questions tagged docker jenkins jenkins-pipeline or ask your own question.
-
-
-
-
-
-
36
-
10
-
13
The Overflow BlogFeatured on MetaHot Meta PostsLinked
75docker error : the input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty'9kubectl exec fails with the error "Unable to use a TTY - input is not a terminal or the right kind of file"Related
Hot Network Questions
-
Would Mermaids Be Affected by Tongue-eating Lice Evolving Alongside Them?
-
Does Manual iso = low noise?
-
Vim cannot find medical spell files
-
Why can PPPoE connect to a gateway which is not in the same subnet
-
What is the text on Neil Armstrong's space suit's left glove?
-
How to say from a Linux block device if it is trimmable or not?
-
SMD high voltage resistors and capacitors
-
Extract left part of field with regexp_substr after two specific charaters
-
Why do constitutions not incorporate a clause on population control?
-
Why doesn't somebody update or improve the Messier catalogue?
-
What would stop megafauna from evolving in low gravity planets?
-
Can black win this pawn ending?
-
Perl conditional (ternary) operator does no shortcut evaluation
-
Is it correct to say one 'estimates' or 'measures' r-squared?
-
Unlolify a lolified message
-
Can I safely drill a hole from the crown into the steerer in my carbon fork?
-
Stiff/binding headset
-
Given the name of a US pharmaceutical drug, how can I know its equivalent in other countries?
-
Prove that sin(x) ≥ x/2, but without calculus!
-
Is it safe to use Category 1 80,000BTU furnace with 2 inch PVC exhaust?
-
Solving integral using feynman trick
-
Does Nicol Bolas, Dragon-God make me lose the game if I only control a nonlegendary planeswalker?
-
Decipher this message for instructions to decipher this message
-
Why is electric heating considered a work interaction?