【问题标题】:How to workaround "the input device is not a TTY" when using grunt-shell to invoke a script that calls docker run?使用 grunt-shell 调用调用 docker run 的脚本时如何解决“输入设备不是 TTY”?
【发布时间】:2017-03-25 00:32:56
【问题描述】:

发出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.

这是Gruntfile.js 命令:

shell: {
  test: {
    command: './run.sh npm test'
  }

这里是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 $@

这里是相关的package.jsonscripts 和命令test:

"scripts": {
  "test": "mocha --color=true -R spec test/*.test.js && npm run lint"
}

我怎样才能让grunt 让docker 对TTY 感到满意?在 grunt 之外执行 ./run.sh npm test 可以正常工作:

$ ./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

【问题讨论】:

    标签: docker gruntjs tty grunt-shell


    【解决方案1】:

    从 docker run 命令中删除-t:

    docker run $RUN_ENV_FILE -i --rm --user node -v "$PWD":/app -w /app yaktor/node:0.39.0 $@
    

    -t 告诉 docker 配置 tty,如果您没有 tty 并尝试附加到容器,这将不起作用(默认情况下当您不执行 -d 时)。

    【讨论】:

      【解决方案2】:

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

      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
      

      如果直接运行,脚本会运行得很好,并且邮件会带有正确的输出。但是,当从cron、(crontab -e) 运行时,邮件将没有内容。围绕权限、shell 和路径等尝试了很多东西。但是没有乐趣!

      终于找到了:

      */20 * * * * scriptblah.sh > $HOME/cron.log 2>&1
      

      在那个cron.log 文件上找到了这个输出:

      输入设备不是 TTY

      搜索把我带到了这里。在我删除 -t 之后,它现在工作得很好!

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

      【讨论】:

        猜你喜欢
        • 2018-04-12
        • 2021-12-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-08-23
        • 2021-04-06
        • 2019-12-24
        相关资源
        最近更新 更多