python - 在Airflow的docker内部运行python脚本

标签 python docker airflow

我有这段代码用于在docker内部执行python脚本的气流:

a02_retrieve_2 = SSHExecuteOperator(
    task_id='a02_retrieve_2',
    ssh_hook=sshHook,
    dag=dag,
    bash_command= 'docker exec myDocker -i bash -c "  /opt/conda/bin/python aretrieve_2.py   --myarg  45  --myarg 35   "  '
)

不幸的是,它不起作用。

但是,不带参数的版本有效。
a02_retrieve_2 = SSHExecuteOperator(
    task_id='a02_retrieve_2',
    ssh_hook=sshHook,
    dag=dag,
    bash_command= 'docker exec myDocker -i bash -c "  /opt/conda/bin/python aretrieve_2.py  "  '
)

错误是:
Python script starts to run but Airflow is unable to catch up the python script parameters...

如何使带有python脚本参数的版本有效?

这和神社模板有关吗?
BashOperator doen't run bash file apache airflow

最佳答案

我通过查看bashoperator的源代码找到了答案:
这使用popen

            self.log.info("Running command: %s", bash_command)
            sp = Popen(
                ['bash', fname],
                stdout=PIPE, stderr=STDOUT,
                cwd=tmp_dir, env=self.env,
                preexec_fn=pre_exec)

https://airflow.incubator.apache.org/_modules/bash_operator.html

关于python - 在Airflow的docker内部运行python脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50036712/

相关文章:

amazon-web-services - 从我的 ec2 实例 ssh 到我的 ec2 实例

python - 根据我的 df 中 ID 的进入和退出时间确定组大小

python - 镜像但尺寸错误

powershell - Windows 10 上的 docker-machine - "You must have a copy of the scp binary locally to use the scp feature"

Docker-compose 无法运行从文件读取配置的 jar

kubernetes - 在 GKE 上部署 Airflow 的最佳方式和生产级别是什么?

python - 使用scrapy时在AWS上获取TCP连接超时: 110: Connection timed out.?

Python 节点转换器 : how to remove nodes?

docker - Kubernetes仪表板不接受仅查看服务帐户 token

airflow - Airflow 运行时自定义 Operator XCom