python - docker exec 上的 Heredoc

标签 python bash shell docker heredoc

我基本上是在尝试让 Flask-migrate 的 shell 与 Flask 应用程序上下文一起执行 heredoc

下面是我试图在我的 bash 脚本中运行的命令

$ docker exec -it mycontainer ./manage shell <<-EOF
    # shell commands to be executed
EOF

当尝试执行上述命令时,我得到:

无法在非 tty 输入上启用 tty 模式

这是管理文件:

#!/usr/bin/env python

from middleware import create_app, config
from middleware.models import db

from flask.ext.script import Manager
from flask.ext.migrate import Migrate, MigrateCommand


app = create_app(config)
migrate = Migrate(app, db)

manager = Manager(app)
manager.add_command('db', MigrateCommand)


if __name__ == '__main__':
    manager.run()

我的问题是有没有办法将像 heredoc 中的命令集传递给 shell?

最佳答案

docker exec 命令中删除 -t 选项以删除附加的 pseudo-TTY 或使用 --tty=false:

docker exec -i mycontainer ./manage shell <<-EOF
    # shell commands to be executed
EOF

否则:

docker exec -i --tty=false mycontainer ./manage shell <<-EOF
    # shell commands to be executed
EOF

关于python - docker exec 上的 Heredoc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34703985/

相关文章:

python - 如何在一个文件中模拟日期时间?

python正则表达式查找所有单词组

linux - 如何在重定向文件时获得提示信息?

linux - linux shell 支持列表数据结构吗?

linux - 如何使用 shell 脚本将可变数量的行从一个文件复制到另一个文件?

python - 如何在X11中捕获另一个按键事件后发送按键事件

java - 所有 Java 标准类和方法的简单列表?

linux - "Couldn' t stat 远程文件 : No such file or directory": Using FTP in shell script from *nix to Win

c - 如何在 C 中将 execv 与生成的路径一起使用?

bash - 如何使用Transform将Unix Bash脚本或awk脚本用作Hive UDF?