docker-compose exec python 输入设备不是 AWS EC2 UserData 中的 TTY

docker-compose exec python the input device is not a TTY in AWS EC2 UserData

我正在使用 EC2 UserData bootstrap 实例。

追踪 bootstrap 执行 /var/log/cloud-init-output.log 的日志,我发现脚本停止在 :

+ docker-compose exec web python /var/www/flask/app/db_fixtures.py
the input device is not a TTY

似乎这个命令在交互模式下是 运行,但为什么呢?以及如何为此命令强制非交互模式(docker-compose exec)?

引自the docker-compose exec docs

Commands are by default allocating a TTY, so you can use a command such as docker-compose exec web sh to get an interactive prompt.

要禁用此行为,您可以使用 -T 标志来禁用 pseudo-tty 分配:

docker-compose exec -T web python /var/www/flask/app/db_fixtures.py

或者在运行之前设置COMPOSE_INTERACTIVE_NO_CLI environment variable为1 docker-compose exec:

export COMPOSE_INTERACTIVE_NO_CLI=1