错误“输入设备不是TTY”

本文探讨了在Jenkins中运行Docker容器时遇到的'The input device is not a TTY'错误,并提供了多种解决方案,包括修改Docker命令参数、使用不同的命令行界面及调整脚本选项。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文翻译自:Error “The input device is not a TTY”

I am running the following command from my Jenkinsfile . 我从我的Jenkinsfile运行以下命令。 However, I get the error "The input device is not a TTY" . 但是,我收到错误“输入设备不是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? 有没有办法从Jenkinsfile运行脚本而不进行交互模式?

I basically have a file called script.sh that I would like to run inside the Docker container. 我基本上有一个名为script.sh的文件,我想在Docker容器中运行。


#1楼

参考:https://stackoom.com/question/2uq32/错误-输入设备不是TTY


#2楼

Remove the -it from your cli to make it non interactive and remove the TTY. 删除-it从你的CLI使其成为非交互式的和删除TTY。 If you don't need either, eg running your command inside of a Jenkins or cron script, you should do this. 如果您不需要,例如在Jenkins或cron脚本中运行命令,则应该执行此操作。

Or you can change it to -i if you have input piped into the docker command that doesn't come from a TTY. 或者,如果您输入了不是来自TTY的docker命令,则可以将其更改为-i If you have something like xyz | docker ... 如果您有类似xyz | docker ...东西 xyz | docker ... or docker ... <input in your command line, do this. xyz | docker ...docker ... <input在命令行docker ... <input ,执行此操作。

Or you can change it to -t if you want TTY support but don't have it available on the input device. 或者,如果您需要TTY支持但在输入设备上没有它,则可以将其更改为-t 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. 或者,如果您需要交互式终端且未在Linux或MacOS上的终端中运行,请使用其他命令行界面。 PowerShell is reported to include this support on Windows. 据报道,PowerShell在Windows上包含此支持。


What is a TTY? 什么是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. 今天它由Linux命令终端和ssh接口提供。 See the wikipedia article for more details . 有关详细信息,请参阅维基百科文章


#3楼

对于那些在Windows上-it此错误和git bash的人,只需使用PowerShell,其中-it可以正常工作。


#4楼

I believe you need to be in a TTY for docker to be able to allocate a TTY (the -t option). 我相信你需要在TTY中为docker分配一个TTY( -t选项)。 Jenkins executes its jobs not in a TTY. 詹金斯不是在TTY中执行其工作。

Having said that, the script you are running within Jenkins you may also want to run locally. 话虽如此,您在Jenkins中运行的脚本可能也想在本地运行。 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. 在这种情况下,分配TTY非常方便,因此您可以在本地运行时发送ctrl + c等信号。

To fix this make your script optionally use the -t option, like so: 要解决此问题,您的脚本可以选择使用-t选项,如下所示:

test -t 1 && USE_TTY="-t" 
docker run ${USE_TTY} ...

#5楼

if using windows, try with cmd , for me it works. 如果使用Windows,尝试用cmd,对我来说它的工作原理。 check if docker is started. 检查docker是否已启动。


#6楼

If you are (like me) using git bash on windows, you just need to put 如果你(像我一样)在Windows上使用git bash,你只需要放

winpty winpty

before your 'docker line' : 在你的'泊坞线'之前:

winpty docker exec -it some_cassandra bash
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值