Quickly setup Apache Airflow 2 in one container
10K+
airflow db upgrade command cannot solve this change if encountered. There are several way to address the problem:
airflow.cfg have been renamed, check the document to ensure that the name of the parameter(s) you passed into the container has the same name and take actions accordingly.By default, docker-airflow runs Airflow with SequentialExecutor :
docker run -d -p 8080:8080 wuuker/docker-airflow webserver
If you want to run another executor, use the other docker-compose.yml files provided in this repository.
For LocalExecutor :
docker-compose -f docker-compose-LocalExecutor.yml up -d
For CeleryExecutor :
docker-compose -f docker-compose-CeleryExecutor.yml up -d
NB : If you want to have DAGs example loaded (default=False), you've to set the following environment variable :
LOAD_EX=n
docker run -d -p 8080:8080 -e LOAD_EX=y wuuker/docker-airflow
If you want to use Ad hoc query, make sure you've configured connections: Go to Admin -> Connections and Edit "postgres_default" set this values (equivalent to values in airflow.cfg/docker-compose*.yml) :
It's possible to set any configuration value for Airflow from environment variables, which are used over values from the airflow.cfg.
The general rule is the environment variable should be named AIRFLOW__<section>__<key>, for example AIRFLOW__CORE__SQL_ALCHEMY_CONN sets the sql_alchemy_conn config option in the [core] section.
Check out the Airflow documentation for more details
You can also define connections via environment variables by prefixing them with AIRFLOW_CONN_ - for example AIRFLOW_CONN_POSTGRES_MASTER=postgres://user:password@localhost:5432/master for a connection called "postgres_master". The value is parsed as a URI. This will work for hooks etc, but won't show up in the "Ad-hoc Query" section unless an (empty) connection is also created in the DB
Airflow allows for custom user-created plugins which are typically found in ${AIRFLOW_HOME}/plugins folder. Documentation on plugins can be found here
In order to incorporate plugins into your docker container
plugins/ with your custom plugins.-v $(pwd)/plugins/:/usr/local/airflow/plugins-v $(pwd)/requirements.txt:/requirements.txt (or add it as a volume in docker-compose file)Easy scaling using docker-compose:
docker-compose -f docker-compose-CeleryExecutor.yml scale worker=5
This can be used to scale to a multi node setup using docker swarm.
If you want to run other airflow sub-commands, such as list_dags or clear you can do so like this:
docker run --rm -ti wuuker/docker-airflow airflow list_dags
or with your docker-compose set up like this:
docker-compose -f docker-compose-CeleryExecutor.yml run --rm webserver airflow list_dags
You can also use this to run a bash shell or any other command in the same environment that airflow would be run in:
docker run --rm -ti wuuker/docker-airflow bash
docker run --rm -ti wuuker/docker-airflow ipython
If the executor type is set to anything else than SequentialExecutor you'll need an SQL database.
Here is a list of PostgreSQL configuration variables and their default values. They're used to compute
the AIRFLOW__CORE__SQL_ALCHEMY_CONN and AIRFLOW__CELERY__RESULT_BACKEND variables when needed for you
if you don't provide them explicitly:
| Variable | Default value | Role |
|---|---|---|
POSTGRES_HOST | postgres | Database server host |
POSTGRES_PORT | 5432 | Database server port |
POSTGRES_USER | airflow | Database user |
POSTGRES_PASSWORD | airflow | Database password |
POSTGRES_DB | airflow | Database name |
POSTGRES_EXTRAS | empty | Extras parameters |
You can also use those variables to adapt your compose file to match an existing PostgreSQL instance managed elsewhere.
Please refer to the Airflow documentation to understand the use of extras parameters, for example in order to configure a connection that uses TLS encryption.
Here's an important thing to consider:
When specifying the connection as URI (in AIRFLOW_CONN_* variable) you should specify it following the standard syntax of DB connections, where extras are passed as parameters of the URI (note that all components of the URI should be URL-encoded).
Therefore you must provide extras parameters URL-encoded, starting with a leading ?. For example:
POSTGRES_EXTRAS="?sslmode=verify-full&sslrootcert=%2Fetc%2Fssl%2Fcerts%2Fca-certificates.crt"
If the executor type is set to CeleryExecutor you'll need a Celery broker. Here is a list of Redis configuration variables
and their default values. They're used to compute the AIRFLOW__CELERY__BROKER_URL variable for you if you don't provide
it explicitly:
| Variable | Default value | Role |
|---|---|---|
REDIS_PROTO | redis:// | Protocol |
REDIS_HOST | redis | Redis server host |
REDIS_PORT | 6379 | Redis server port |
REDIS_PASSWORD | empty | If Redis is password protected |
REDIS_DBNUM | 1 | Database number |
You can also use those variables to adapt your compose file to match an existing Redis instance managed elsewhere.
I'd bind some directories in the container, listed below, to somewhere on my host machine, so I can my run own DAGs, keep event logs, and add plugins:
/usr/local/airflow/dags/usr/local/airflow/plugins/usr/local/airflow/logsContent type
Image
Digest
Size
374.2 MB
Last updated
over 4 years ago
docker pull wuuker/docker-airflow