とあるCIの処理内で、docker-composeコマンド(最近だとdocker composeコマンド)でのエラーの話。
現象
CI内で以下のようなコマンドを実行して、標準出力でデータベースの一覧を出力しようとしました。
$ docker-compose exec db mysql -e "show databases;"
すると、以下のような出力だけされて、SQLの結果が出力されませんでした。。
the input device is not a TTY
解決策
コマンドに、-T
のオプションをつけることで解決しました。
$ docker-compose exec -T db mysql -e "show databases;"
-Tオプションについて
helpで-T
のオプションをちらっと見てみました。
$ docker compose exec --help Usage: docker compose exec [options] [-e KEY=VAL...] [--] SERVICE COMMAND [ARGS...] Execute a command in a running container. Options: -d, --detach Detached mode: Run command in the background. -e, --env stringArray Set environment variables --index int index of the container if there are multiple instances of a service [default: 1]. (default 1) -T, --no-TTY docker compose exec Disable pseudo-TTY allocation. By default docker compose exec allocates a TTY. --privileged Give extended privileges to the process. -u, --user string Run the command as this user. -w, --workdir string Path to workdir directory for this command.
Disable pseudo-TTY allocation. By default docker compose exec allocates a TTY.
ということで、DeepLによると、疑似TTYの割り当てを無効にする。デフォルトでは、docker compose execはTTYを割り当てます。とのことらしいです。
デフォルトではTTYが割り当てられているので、TTYの割当を無効にすることで解決できたみたいです。ふーん。