Skip to main content

Running Airflow locally with DataHub


This document describes how you can run Airflow side-by-side with DataHub's docker images to test out Airflow lineage with DataHub. This offers a much easier way to try out Airflow with DataHub, compared to configuring containers by hand, setting up configurations and networking connectivity between the two systems.


  • Docker: ensure that you have a working Docker installation and you have at least 8GB of memory to allocate to both Airflow and DataHub combined.
docker info | grep Memory
> Total Memory: 7.775GiB

Step 1: Set up your Airflow area#

  • Create an area to host your airflow installation
  • Download the docker-compose file hosted in DataHub's repo in that directory
  • Download a sample dag to use for testing Airflow lineage
mkdir -p airflow_installcd airflow_install# Download docker-composecurl -L '' -o docker-compose.yaml# Create dags directorymkdir -p dags# Download a sample DAGcurl -L '' -o dags/

What is different between this docker-compose file and the official Apache Airflow docker compose file?#

  • This docker-compose file is derived from the official Airflow docker-compose file but makes a few critical changes to make interoperability with DataHub seamless.
  • The Airflow image in this docker compose file extends the base Apache Airflow docker image and is published here. It includes the latest acryl-datahub pip package installed by default so you don't need to install it yourself.
  • This docker-compose file sets up the networking so that
    • the Airflow containers can talk to the DataHub containers through the datahub_network bridge interface.
    • Modifies the port-forwarding to map the Airflow Webserver port 8080 to port 58080 on the localhost (to avoid conflicts with DataHub metadata-service, which is mapped to 8080 by default)
  • This docker-compose file also sets up the ENV variables to configure Airflow's Lineage Backend to talk to DataHub. (Look for the AIRFLOW__LINEAGE__BACKEND and AIRFLOW__LINEAGE__DATAHUB_KWARGS variables)

Step 2: Bring up Airflow#

docker-compose up

You should see a host of messages as Airflow starts up.

Container airflow_deploy_airflow-scheduler_1  Started                                                                               15.7sAttaching to airflow-init_1, airflow-scheduler_1, airflow-webserver_1, airflow-worker_1, flower_1, postgres_1, redis_1airflow-worker_1     | BACKEND=redisairflow-worker_1     | DB_HOST=redisairflow-worker_1     | DB_PORT=6379airflow-worker_1     | airflow-webserver_1  | airflow-init_1       | DB: postgresql+psycopg2://airflow:***@postgres/airflowairflow-init_1       | [2021-08-31 20:02:07,534] {} INFO - Creating tablesairflow-init_1       | INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.airflow-init_1       | INFO  [alembic.runtime.migration] Will assume transactional DDL.airflow-scheduler_1  |   ____________       _____________airflow-scheduler_1  |  ____    |__( )_________  __/__  /________      __airflow-scheduler_1  | ____  /| |_  /__  ___/_  /_ __  /_  __ \_ | /| / /airflow-scheduler_1  | ___  ___ |  / _  /   _  __/ _  / / /_/ /_ |/ |/ /airflow-scheduler_1  |  _/_/  |_/_/  /_/    /_/    /_/  \____/____/|__/airflow-scheduler_1  | [2021-08-31 20:02:07,736] {} INFO - Starting the schedulerairflow-scheduler_1  | [2021-08-31 20:02:07,736] {} INFO - Processing each file at most -1 timesairflow-scheduler_1  | [2021-08-31 20:02:07,915] {} INFO - Launched DagFileProcessorManager with pid: 25airflow-scheduler_1  | [2021-08-31 20:02:07,918] {} INFO - Resetting orphaned tasks for active dag runsairflow-scheduler_1  | [2021-08-31 20:02:07,923] {} INFO - Configured default timezone Timezone('UTC')flower_1             | airflow-worker_1     |  * Serving Flask app "airflow.utils.serve_logs" (lazy loading)airflow-worker_1     |  * Environment: productionairflow-worker_1     |    WARNING: This is a development server. Do not use it in a production deployment.airflow-worker_1     |    Use a production WSGI server instead.airflow-worker_1     |  * Debug mode: offairflow-worker_1     | [2021-08-31 20:02:09,283] {} INFO -  * Running on (Press CTRL+C to quit)flower_1             | BACKEND=redisflower_1             | DB_HOST=redisflower_1             | DB_PORT=6379flower_1             | 

Finally, Airflow should be healthy and up on port 58080.

airflow-webserver_1  | - - [31/Aug/2021:20:30:52 +0000] "GET /static/appbuilder/fonts/fontawesome-webfont.woff2?v=4.7.0 HTTP/1.1" 304 0 "http://localhost:58080/static/appbuilder/css/font-awesome.min.css" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36"airflow-init_1       | Admin user airflow createdairflow-init_1       | 2.1.3airflow_install_airflow-init_1 exited with code 0

Navigate to http://localhost:58080 to confirm and find your Airflow webserver. Default username and password is:


Step 4: Register DataHub connection (hook) to Airflow#

docker exec -it `docker ps | grep webserver | cut -d " " -f 1` airflow connections add --conn-type 'datahub_rest' 'datahub_rest_default' --conn-host 'http://datahub-gms:8080'


Successfully added `conn_id`=datahub_rest_default : datahub_rest://:@http://datahub-gms:8080:

What is the above command doing?#

  • Find the container running airflow webserver: docker ps | grep webserver | cut -d " " -f 1
  • Running the airflow connections add ... command inside that container to register the datahub_rest connection type and connect it to the datahub-gms host on port 8080.
  • Note: This is what requires Airflow to be able to connect to datahub-gms the host (this is the container running datahub-gms image) and this is why we needed to connect the Airflow containers to the datahub_network using our custom docker-compose file.

Step 3: Find the DAGs and run it#

Navigate the Airflow UI to find the sample Airflow dag we just brought in

Find the DAG

By default, Airflow loads all DAG-s in paused status. Unpause the sample DAG to use it. Paused DAG Unpaused DAG

Then trigger the DAG to run.

Trigger the DAG

After the DAG runs successfully, go over to your DataHub instance to see the Pipeline and navigate its lineage.

DataHub Pipeline View

DataHub Pipeline Entity

DataHub Task View

DataHub Lineage View


Most issues are related to connectivity between Airflow and DataHub.

Here is how you can debug them.

Find the Task Log

Inspect the Log

In this case, clearly the connection datahub-rest has not been registered. Looks like we forgot to register the connection with Airflow! Let's execute Step 4 to register the datahub connection with Airflow.

After re-running the DAG, we see success!

Pipeline Success