diff --git a/docs/apache-airflow/howto/docker-compose/index.rst b/docs/apache-airflow/howto/docker-compose/index.rst index 6e75ef84169ea..e4d169c0ea72d 100644 --- a/docs/apache-airflow/howto/docker-compose/index.rst +++ b/docs/apache-airflow/howto/docker-compose/index.rst @@ -271,6 +271,40 @@ to rebuild the images on-the-fly when you run other ``docker compose`` commands. Examples of how you can extend the image with custom providers, python packages, apt packages and more can be found in :doc:`Building the image `. +Special case - adding dependencies via requirements.txt file +============================================================ + +Usual case for custom images, is when you want to add a set of requirements to it - usually stored in +``requirements.txt`` file. For development, you might be tempted to add it dynamically when you are +starting the original airflow image, but this has a number of side effects (for example your containers +will start much slower - each additional dependency will further delay your containers start up time). +Also it is completely unnecessary, because docker compose has the development workflow built-in. +You can - following the previous chapter, automatically build and use your custom image when you +iterate with docker compose locally. Specifically when you want to add your own requirement file, +you should do those steps: + +1) Comment out the ``image: ...`` line and remove comment from the ``build: .`` line in the + ``docker-compose.yaml`` file. The relevant part of the docker-compose file of yours should look similar + to (use correct image tag): + +``` +#image: ${AIRFLOW_IMAGE_NAME:-apache/airflow:2.5.1} +build: . +``` + +2) Create ``Dockerfile`` in the same folder your ``docker-compose.yaml`` file is with content similar to: + +``` +FROM apache/airflow:2.5.1 +ADD requirements.txt . +RUN pip install -r requirements.txt +``` + +3) Place ``requirements.txt`` file in the same directory. + +Run ``docker compose build`` to build the image, or add ``--build`` flag to ``docker compose up`` or +``docker compose run`` commands to build the image automatically as needed. + Networking ==========