danimille
danimille

Reputation: 350

Reading files on local machine from docker container

I am running airflow from a docker image called puckel/docker-airflow. I synchronized my local dags folder with container airflow folder when I started the container using following docker command:

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). The function is as follows:

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:

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.

Thanks for your time!

Upvotes: 2

Views: 2146

Answers (1)

scenox
scenox

Reputation: 718

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").

Upvotes: 1

Related Questions