Skip to content

DockerOperator loosing some initial container output #9190

Description

@the-horhe

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),
)

print_hello_world = 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

Output without logs=True but with slow starting container (command /bin/bash -c \'sleep 5 && echo "HELLO WORLD!"\'):
image
^ ok - notice string with "INFO - HELLO WORLD!"

Output with original command and logs=True:
image
^ ok - notice string with "INFO - HELLO WORLD!"

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions