Introduction
Airflow can be deployed in many ways. In this post we demonstrate how to deploy Airflow with Docker Compose.
Prerequisites
- Docker CE, Docker Desktop, or OrbStack installed
- Docker Compose version
v2.14.0
or newer - At least 4GB of RAM
Download configuration file
To deploy Airflow with Docker Compose we first need the docker-compose.yaml
file. Download it from the Airflow website or run:
|
|
Components
The configuration file defines the components required by Airflow:
airflow-scheduler
– monitors DAGs and tasks, triggering task instances when dependencies are metairflow-webserver
– Airflow web interface available athttp://localhost:8080
airflow-worker
– executes tasks assigned by the schedulerairflow-triggerer
– runs event loops for deferrable tasksairflow-init
– initialization servicepostgres
– databaseredis
– broker that forwards messages from the scheduler to workers
Start Airflow services
By default the configuration starts Airflow with CeleryExecutor
and binds several directories into the containers. The root directory can be configured through AIRFLOW_PROJ_DIR
in the .env
file. If not set, the directory where you run docker-compose
is mounted and the following subdirectories are created:
dags
– place DAG fileslogs
– contains task and scheduler logsconfig
– add custom log formatters orairflow_local_settings.py
plugins
– place custom plugins
Before starting the services, add the following to .env
:
|
|
Then start the services:
|
|
The Airflow web UI is available at http://localhost:8080
.
Configuration guide
Set Airflow image version
The script pulls image v2.10.0
from Docker Hub by default. To change the version, set the following variable in .env
:
|
|
Monitor Celery with Flower
Flower
is disabled by default. Enable it with:
|
|
or
|
|
The Flower UI is available at http://localhost:5555
.
Use a custom image
Build while starting
Docker Compose allows building images when starting containers instead of building them beforehand. See the Docker Compose build documentation.
Build ahead of time
Build the image first and specify it with the
AIRFLOW_IMAGE_NAME
variable.
Clean up
To stop Airflow and clean up generated data and unused containers:
|
|