0

我正在使用 Windows 机器并创建了气流容器。我可以通过 DAG 读取本地文件系统上的数据,但无法将数据写入文件。我也尝试过给出完整路径,也尝试过不同的运算符:Python 和 Bash,但它仍然不起作用。DAG 成功,没有任何失败可显示。注意: /opt/airflow : 是 $AIRFLOW_HOME 路径

可能是什么原因?

一段代码:

from airflow import DAG
from datetime import datetime
from airflow.operators.python import PythonOperator
from airflow.operators.bash import BashOperator


def pre_process():
    f = open("/opt/airflow/write.txt", "w")
    f.write("world")
    f.close()


with DAG(dag_id="test_data", start_date=datetime(2021, 11, 24), schedule_interval='@daily') as dag:
    check_file = BashOperator(
        task_id="check_file",
        bash_command="echo Hi > /opt/airflow/hi.txt "
    )
    pre_processing = PythonOperator(
        task_id="pre_process",
        python_callable=pre_process
    )
    check_file >> pre_processing
4

1 回答 1

0

它可能是写在运行气流的容器中的。

您需要了解容器的工作原理。它们提供了隔离,但这也意味着除非您进行一些数据共享,否则您在容器中创建的任何内容都保留在容器中,并且您在容器之外看不到它(这就是容器隔离的全部意义所在)。

您通常可以通过docker exec命令https://docs.docker.com/engine/reference/commandline/exec/进入容器,或者您可以 - 例如 - 将一个文件夹从您的主机安装到您的容器并在那里写入您的文件(到目前为止据我所知,默认情况下,在 Windows 中会为您安装一些文件夹 - 但您需要查看 docker 文档)。

于 2021-11-27T13:47:28.607 回答