the-horhe opened a new issue #9190:
URL: https://github.com/apache/airflow/issues/9190


   **Apache Airflow version**: 1.10.10
   
   **Environment**: official docker image apache/airflow:1.10.10, docker api 
version: 1.40
   
   **What happened**:
   Don't see any container output in task logs when using DockerOperator with 
short living containers.
   
   **What you expected to happen**:
   Expected to see container stdout/stderr
   
   It seems the problem is here: 
https://github.com/apache/airflow/blob/v1-10-stable/airflow/operators/docker_operator.py#L232
   1. Containers is being started
   2. We attach to container output
   
   But all output between steep 1 and to 2 seems to be lost.
   
   I found a simple solution - adding `logs=True` to self.cli.attach fixes the 
problem
   
https://github.com/apache/airflow/blob/v1-10-stable/airflow/operators/docker_operator.py#L235
   According to docker API documentation 
(https://docs.docker.com/engine/api/v1.40.yaml - line 6052) solution seems 
legit.
   
   **How to reproduce it**:
   
   ```
   from datetime import timedelta
   from airflow.utils.dates import days_ago
   from airflow import DAG
   from airflow.operators.docker_operator import DockerOperator
   
   
   default_args = {
       'owner': 'airflow',
       'depends_on_past': True,
       'wait_for_downstream': True,
       'catchup': True,
       'start_date': days_ago(2),
       'retries': 1,
       'retry_delay': timedelta(minutes=5),
   }
   dag = DAG(
       'docker_dag',
       default_args=default_args,
       description='',
       schedule_interval=timedelta(days=1),
   )
   
   run_gsc_crawlers = DockerOperator(
       task_id='print_hello_world',
       image='centos:latest',
       api_version='auto',
       auto_remove=True,
       command='/bin/bash -c \'echo "HELLO WORLD!"\'',
       docker_url='unix://var/run/docker.sock',
       network_mode='bridge',
       dag=dag,
   )
   ```
   Output without logs=True:
   
![image](https://user-images.githubusercontent.com/12816025/84119285-d0704600-aa3c-11ea-8f4b-f7a12a889c24.png)
   
   Output without logs=True but with slow starting container (command 
`/bin/bash -c \'sleep 5 && echo "HELLO WORLD!"\'`):
   
![image](https://user-images.githubusercontent.com/12816025/84119528-2ba23880-aa3d-11ea-9186-bc0a9e2d0ffe.png)
   ^ ok - notice string with "INFO - HELLO WORLD!"
   
   Output with original command and logs=True:
   
![image](https://user-images.githubusercontent.com/12816025/84119853-ab300780-aa3d-11ea-801d-1155b02732e0.png)
   ^ ok - notice string with "INFO - HELLO WORLD!"


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to