错误“输入设备不是 TTY" [英] Error "The input device is not a TTY"

查看:40
本文介绍了错误“输入设备不是 TTY"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从我的 Jenkinsfile 运行以下命令.但是,我收到错误输入设备不是 TTY".

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

有没有办法在不进行交互模式的情况下从 Jenkinsfile 运行脚本?

Is there a way to run the script from the Jenkinsfile without doing interactive mode?

我基本上有一个名为 script.sh 的文件,我想在 Docker 容器中运行它.

I basically have a file called script.sh that I would like to run inside the Docker container.

推荐答案

从您的 cli 中删除 -it 以使其非交互式并删除 TTY.如果您也不需要,例如在 Jenkins 或 cron 脚本中运行你的命令,你应该这样做.

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.

或者您可以将其更改为 -i,如果您已通过管道输入不是来自 TTY 的 docker 命令.如果你有类似 xyz | 的东西docker ...docker ... 在您的命令行中,执行此操作.

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.

或者,如果您想要 TTY 支持但在输入设备上没有它,您可以将其更改为 -t.为检查 TTY 以启用日志中输出的颜色格式的应用程序执行此操作,或者当您稍后使用适当的终端连接到容器时执行此操作.

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.

或者,如果您需要一个交互式终端并且不在 Linux 或 MacOS 上的终端中运行,请使用不同的命令行界面.据报道,PowerShell 在 Windows 上包含此支持.

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.

什么是 TTY?它是一个支持转义序列、移动光标等的终端界面,它来自连接到大型机的过去的哑终端.今天它由 Linux 命令终端和 ssh 接口提供.请参阅维基百科文章了解详情.

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.

要查看运行带有和不带有 TTY 的容器的区别,请运行不带 TTY 的容器:docker run --rm -i ubuntu bash.从该容器内部,使用 apt-get update 安装 vim;apt-get 安装 vim.请注意缺少提示.对文件运行 vim 时,尝试在文件内移动光标.

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 with apt-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.

这篇关于错误“输入设备不是 TTY"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆