Got the answer at airflow GitHub discussions. The only way now to install extra python packages to build your own image. I will try to explain this solution in more details
Step 1. Put Dockerfile
, docker-compose.yaml
and requirements.txt
files to the project directory
Step 2. Paste to Dockefile code below:
FROM apache/airflow:2.1.0
COPY requirements.txt .
RUN pip install -r requirements.txt
Step 3. Paste to docker-compose.yaml
code, which you can find in the official documentation. Replace section image: ${AIRFLOW_IMAGE_NAME:-apache/airflow:2.1.0}
with build: .
:
---
version: '3'
x-airflow-common:
&airflow-common
build: .
# REPLACED # image: ${AIRFLOW_IMAGE_NAME:-apache/airflow:2.1.0}
environment:
&airflow-common-env
AIRFLOW__CORE__EXECUTOR: CeleryExecutor
AIRFLOW__CORE__SQL_ALCHEMY_CONN: postgresql+psycopg2://airflow:airflow@postgres/airflow
AIRFLOW__CELERY__RESULT_BACKEND: db+postgresql://airflow:airflow@postgres/airflow
AIRFLOW__CELERY__BROKER_URL: redis://:@redis:6379/0
AIRFLOW__CORE__FERNET_KEY: ''
AIRFLOW__CORE__DAGS_ARE_PAUSED_AT_CREATION: 'true'
AIRFLOW__CORE__LOAD_EXAMPLES: 'false'
AIRFLOW__API__AUTH_BACKEND: 'airflow.api.auth.backend.basic_auth'
volumes:
- ./dags:/opt/airflow/dags
- ./logs:/opt/airflow/logs
- ./plugins:/opt/airflow/plugins
user: "${AIRFLOW_UID:-50000}:${AIRFLOW_GID:-50000}"
depends_on:
redis:
condition: service_healthy
postgres:
condition: service_healthy
# ...
Your project directory at this moment should look like this:
airflow-project
|docker-compose.yaml
|Dockerfile
|requirements.txt
Step 4. Run docker-compose up
to start Airflow, docker-compose
should build your image automatically from Dockerfile
. Run docker-compose build
to rebuild the image and update dependencies
requirements.txt
is used incl. PyCharm for installing dependencies locally – Gristede