简体   繁体   English

从 docker 容器读取本地机器上的文件

[英]Reading files on local machine from docker container

I am running airflow from a docker image called puckel/docker-airflow.我正在从名为 puckel/docker-airflow 的 docker 映像运行 airflow。 I synchronized my local dags folder with container airflow folder when I started the container using following docker command:当我使用以下 docker 命令启动容器时,我将本地 dags 文件夹与容器 airflow 文件夹同步:

docker run -d -p 8080:8080 -v <local_path>:/usr/local/airflow/dags puckel/docker-airflow webserver

On my DAG I have a PythonOperator that calls a function named start_script , this function basically read and initialization files to extracts some information (for example passwords).在我的 DAG 上,我有一个PythonOperator调用名为start_script的 function ,这个 function 基本上读取和初始化文件以提取一些信息(例如密码)。 The function is as follows: function如下:

def start_script():
    config_parser = configparser.RawConfigParser()
    config_parser.read("C:/dags/file.ini")
    pwd= config_parser.get("LOGS", "pwd")

When I run this function locally, the function is able to read the file and bring the password, unfortunatly when I run on docker with dags test command it returns the follow error:当我在本地运行这个 function 时,function 能够读取文件并带上密码,不幸的是,当我在 docker 上运行时,它会返回错误:d

configparser.NoSectionError: No section: 'LOGS'

What is the correct way to call for files in my local machine from a container?从容器调用本地计算机中文件的正确方法是什么? I really think that when I run the function on container the function is not recognizing the path that config_parser should read.我真的认为,当我在容器上运行 function 时,function 无法识别 config_parser 应该读取的路径。

Thanks for your time!谢谢你的时间!

Within the container, you have to point to the config file in the mounted volume, so change config_parser.read("C:/dags/file.ini") to config_parser.read("/usr/local/airflow/dags/file.ini") .在容器中,您必须指向已安装卷中的配置文件,因此将config_parser.read("C:/dags/file.ini")更改为config_parser.read("/usr/local/airflow/dags/file.ini")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM