当使用grunt-shell调用调用docker run的脚本时,如何解决"输入设备不是TTY"?

Mat*_*ams 27 tty gruntjs docker grunt-shell

发布时grunt shell:test,我收到警告"输入设备不是TTY"并且不想使用-f:

$ grunt shell:test
Running "shell:test" (shell) task
the input device is not a TTY
Warning: Command failed: /bin/sh -c ./run.sh npm test
the input device is not a TTY
 Use --force to continue.

Aborted due to warnings.
Run Code Online (Sandbox Code Playgroud)

这是Gruntfile.js命令:

shell: {
  test: {
    command: './run.sh npm test'
  }
Run Code Online (Sandbox Code Playgroud)

这是run.sh:

#!/bin/sh
# should use the latest available image to validate, but not LATEST
if [ -f .env ]; then
  RUN_ENV_FILE='--env-file .env'
fi
docker run $RUN_ENV_FILE -it --rm --user node -v "$PWD":/app -w /app yaktor/node:0.39.0 $@
Run Code Online (Sandbox Code Playgroud)

这是package.json scripts与命令相关的test:

"scripts": {
  "test": "mocha --color=true -R spec test/*.test.js && npm run lint"
}
Run Code Online (Sandbox Code Playgroud)

我怎样才能gruntdockerTTY感到满意?./run.sh npm test在grunt之外执行工作正常:

$ ./run.sh npm test

> yaktor@0.59.2-pre.0 test /app
> mocha --color=true -R spec test/*.test.js && npm run lint


[snip]

  105 passing (3s)


> yaktor@0.59.2-pre.0 lint /app
> standard --verbose
Run Code Online (Sandbox Code Playgroud)

BMi*_*tch 63

-t从docker run命令中删除:

docker run $RUN_ENV_FILE -i --rm --user node -v "$PWD":/app -w /app yaktor/node:0.39.0 $@
Run Code Online (Sandbox Code Playgroud)

-t告诉泊坞窗配置TTY,如果你没有一个tty这将无法正常工作,并尝试连接到容器(默认情况下,你不这样做-d).


小智 5

这为我解决了一个烦人的问题。该脚本有以下几行:

docker exec **-it**  $( docker ps | grep mysql | cut -d' ' -f1)  mysql --user= ..... > /var/tmp/temp.file
mutt -s "File is here" someone@somewhere.com < /var/tmp/temp.file
Run Code Online (Sandbox Code Playgroud)

如果直接运行该脚本,它将运行得很好,并且邮件将带有正确的输出。但是,从croncrontab -e)运行时,该邮件将不包含任何内容。尝试了许多关于权限,shell和路径等的事情。但是,不要高兴!

终于发现了这一点:

*/20 * * * * scriptblah.sh > $HOME/cron.log 2>&1
Run Code Online (Sandbox Code Playgroud)

在该cron.log文件上找到以下输出:

输入设备不是TTY

搜索将我引到这里。在我删除之后-t,它现在运行良好!

docker exec **-i**  $( docker ps | grep mysql | cut -d' ' -f1)  mysql --user= ..... > /var/tmp/temp.file
Run Code Online (Sandbox Code Playgroud)