スクリプトはttyなしでコマンドを実行しません。

スクリプトはttyなしでコマンドを実行しません。

私はこれをscriptDockerコンテナのエントリポイントとして使用し、そのコンテナで発生したすべてのことをマウントされたボリュームのファイルに書き込もうとしています。 ttyがある場合、これはうまく機能します。

$ docker run -t --rm --privileged -v $PWD:/log rhel7:7.7 /usr/bin/script /log/out.script --timing=/log/out.timing -f -e -c 'echo "hello world"; sleep 10; echo "goodbye world"'
Last login: Tue Jan 21 00:45:14 UTC 2020 on pts/41
Script started, file is /log/out.script
hello world
goodbye world
Script done, file is /log/out.script

ただし、TTYを削除すると、スクリプトは "-c"コマンドを実行しません。

$ docker run --rm --privileged -v $PWD:/log rhel7:7.7 /usr/bin/script /log/out.script --timing=/log/out.timing -f -e -c 'echo "hello world"; sleep 10; echo "goodbye world"'
Last login: Tue Jan 21 00:50:39 UTC 2020 on pts/41
Script started, file is /log/out.script
Script done, file is /log/out.script
$ ls -s out.*
0 out.script  0 out.timing

残念ながら、私が実行したい環境にはコンテナのTTYはありません。スクリプトがこのような動作をするのはなぜですか?回避策がありますか?

ベストアンサー1

このscriptコマンドは、端末出力をキャプチャするように設計されています。端末がないと動作しません。

tee次のコマンドを確認してください。

foo 2>&1 | tee /my/output

foo標準ドッカー出力に出力を送信します。そして指定したファイルにコピーします。

おすすめ記事