Python 带有WSL2后端的Apache DockerOperator卷(Windows主机)
我正在DAG中使用Apache Airflow的Python 带有WSL2后端的Apache DockerOperator卷(Windows主机),python,docker,airflow,Python,Docker,Airflow,我正在DAG中使用Apache Airflow的DockerOperator。对于旧的Windows Linux后端子系统(WSL1),我将卷提供给DockerOperator,如下所示: docker_op = DockerOperator( command=cmd, task_id=task_id, image="{}/{}:{}".format(self.docker_server, self.do
DockerOperator
。对于旧的Windows Linux后端子系统(WSL1),我将卷提供给DockerOperator
,如下所示:
docker_op = DockerOperator(
command=cmd,
task_id=task_id,
image="{}/{}:{}".format(self.docker_server, self.docker_repo_name, self.docker_image_tag),
api_version="auto",
auto_remove=True,
network_mode=self.docker_network,
force_pull=False,
volumes=self.docker_volumes,
dag=self.dag
)
其中self.docker_volumes=['/c/Users/kevin/dev/myproject/app:/app']
不幸的是,当Airflow试图执行docker_op
时,出现以下错误:
python: can't open file '/app/main.py': [Errno 2] No such file or directory
因此,似乎卷的安装不正确。对于旧的WSL1后端,这是可行的,因为DockerRoperator创建的容器构建为“同级”容器,因此与主机共享相同的docker deamon,在本例中为我的笔记本电脑。在阅读和阅读文章后,我还尝试调整卷的主机端路径,例如self.docker_volumes=['/mnt/c/Users/kevin/dev/myproject/app:/app']
,但这也导致了同样的错误
所以,我认为这个问题通常与WSL2后端有关。为了验证这一想法,我尝试了一个非常简单的工作流:我创建了一个包含以下内容的文件main.py
:
print('Hello from inside the container!!!')
我将该文件放在这里C://Users/kevin/dev/wsl2test/main.py
,并从一个简单的Windows Powershell执行以下命令:
docker run -v /c/Users/kevin/ks_dev/wsl2test:/wsl2test python:3 python /wsl2test/main.py
结果是:
Hello from inside the container!!!
我还在WSL2内部运行的Ubuntu shell中执行了类似的命令:
docker run -v /mnt/c/Users/kevin/ks_dev/wsl2test:/wsl2test python:3 python /wsl2test/main.py
结果也是:
Hello from inside the container!!!
因此,通过指定卷的正确主机路径,通常可以将文件装载到具有WSL2后端的docker容器中。然后,自然的问题是:为什么apache airflow的DockerOperator
不起作用