docker-airflow icon indicating copy to clipboard operation
docker-airflow copied to clipboard

DockerOperator accepts only absolute volumes

Open ooverandout opened this issue 5 years ago • 3 comments

Hi!

I am trying to build my own docker-compose with an option to use DockerOperator. I want to create a file with DockerOperator and copy it to my localhost. The only way to do that seems with volumes. It works well, however they require absolute path - this is a problem, because you have to adjust the DAG on the different environment.

Below is my current task.

task1 = DockerOperator(
                task_id='docker_command',
                image='sqlplus_image',
                api_version='auto',
                auto_remove=True,
		volumes=['/home/adam/path/to_dir:/files'],
                command=task1_command,
                docker_url="unix://var/run/docker.sock",
                network_mode="bridge",
		dag=dag
        )

I've tried to do something like : volumes=['/$(pwd)/rest_of_the_path:/files'], or volumes=[os.getcwd() + '/rest_of_the_path:/files'], but it did not work. I've also tried to use python libraries to fetch current working directory, but because this is in docker, it fetches the path from airflow docker container,not from my local host. Any ideas?

ooverandout avatar Jun 04 '19 14:06 ooverandout

You need to mount the socket on the host into the container:

    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

darkn3rd avatar Jun 21 '19 00:06 darkn3rd

You can use airflow variables (and set this path in airflow admin) or environmental variables in docker.

I know this is old post, but this is still an issue and this answer might help someone else.

illmoded avatar May 11 '20 17:05 illmoded

You can use airflow variables (and set this path in airflow admin) or environmental variables in docker.

I know this is old post, but this is still an issue and this answer might help someone else.

can you please elaborate with an example?

eduedix avatar Dec 08 '20 17:12 eduedix