Airflow DockerOperator – Run a script in a running docker container
My question is quite simple I guess.
I would like to use the DockerOperator to run a python script inside of a container, but I do not want to pull or run the container because my target container is already alive (already started). So, what I am expecting is just to run the python script using the command parameter (command="python my_python_script.py")
with DAG('mydag',default_args=args,schedule_interval='@daily', catchup=False) as dag:
task_1=DockerOperator(
task_id='run_task1',
image='ABCDFG',
container_name="EFGHIJKL",
api_version='auto',
auto_remove=False,
user="root",
working_dir="/mydirt",
command="python my_python_script.py",
docker_url="unix://var/run/docker.sock"
)
I already tried different approaches to do this, but I could not achieve the expected result so far.
Does anyone has an idea in how to proceed in this case? I started thinking this is not possible.
Source: Docker Questions