Heredoc在码头工程师

时间:2016-01-10 09:39:25

标签: python bash shell docker heredoc

我基本上试图让Flask-migrate的shell使用Flask app context执行heredoc

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

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

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

cannot enable tty mode on non tty input

这是管理文件:

#!/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?

1 个答案:

答案 0 :(得分:8)

-t命令中删除docker exec选项以删除附加的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