the input device is not a TTY

匿名 (未验证) 提交于 2019-12-03 02:13:02

问题:

I 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

回答1:

Remove 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 like xyz | docker ... or docker ... <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 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 color output, 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.



回答2:

For those who struggle with this error and git bash on Windows, just use PowerShell where -it works perfectly.



回答3:

I 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} ... 


回答4:

if using windows, try with cmd , for me it works. check if docker is started.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!