可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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.