Skip to content

Commit 7155c10

Browse files
potiukjedcunningham
authored andcommitted
Add requirements.txt example to "extending docker" (#26663)
When extending the image, there was an example of adding individual packages via PyPI, but not requirements.txt. This PR fixes it. (cherry picked from commit 25fdb2c)
1 parent 45a461b commit 7155c10

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
lines changed

docs/docker-stack/build.rst

+31-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ Quick start scenarios of image extending
2727
----------------------------------------
2828

2929
The most common scenarios where you want to build your own image are adding a new ``apt`` package,
30-
adding a new ``PyPI`` dependency and embedding DAGs into the image.
30+
adding a new ``PyPI`` dependency (either individually or via requirements.txt) and embedding DAGs
31+
into the image.
32+
3133
Example Dockerfiles for those scenarios are below, and you can read further
3234
for more complex cases which might involve either extending or customizing the image. You will find
3335
more information about more complex scenarios below, but if your goal is to quickly extend the Airflow
@@ -46,8 +48,8 @@ switch to the ``root`` user when running the ``apt`` commands, but do not forget
4648
:end-before: [END Dockerfile]
4749

4850

49-
Adding a new ``PyPI`` package
50-
.............................
51+
Adding new ``PyPI`` packages individually
52+
.........................................
5153

5254
The following example adds ``lxml`` python package from PyPI to the image. When adding packages via
5355
``pip`` you need to use the ``airflow`` user rather than ``root``. Attempts to install ``pip`` packages
@@ -58,6 +60,19 @@ as ``root`` will fail with an appropriate error message.
5860
:start-after: [START Dockerfile]
5961
:end-before: [END Dockerfile]
6062

63+
Adding packages from requirements.txt
64+
.....................................
65+
66+
The following example adds few python packages from ``requirements.txt`` from PyPI to the image.
67+
Note that similarly when adding individual packages, you need to use the ``airflow`` user rather than
68+
``root``. Attempts to install ``pip`` packages as ``root`` will fail with an appropriate error message.
69+
70+
.. exampleinclude:: docker-examples/extending/add-requirement-packages/Dockerfile
71+
:language: Dockerfile
72+
:start-after: [START Dockerfile]
73+
:end-before: [END Dockerfile]
74+
75+
6176
Embedding DAGs
6277
..............
6378

@@ -363,6 +378,19 @@ The following example adds ``lxml`` python package from PyPI to the image.
363378
:start-after: [START Dockerfile]
364379
:end-before: [END Dockerfile]
365380

381+
Example of adding packages from requirements.txt
382+
................................................
383+
384+
The following example adds few python packages from ``requirements.txt`` from PyPI to the image.
385+
Note that similarly when adding individual packages, you need to use the ``airflow`` user rather than
386+
``root``. Attempts to install ``pip`` packages as ``root`` will fail with an appropriate error message.
387+
388+
.. exampleinclude:: docker-examples/extending/add-requirement-packages/Dockerfile
389+
:language: Dockerfile
390+
:start-after: [START Dockerfile]
391+
:end-before: [END Dockerfile]
392+
393+
366394
Example when writable directory is needed
367395
.........................................
368396

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one or more
2+
# contributor license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright ownership.
4+
# The ASF licenses this file to You under the Apache License, Version 2.0
5+
# (the "License"); you may not use this file except in compliance with
6+
# the License. You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# This is an example Dockerfile. It is not intended for PRODUCTION use
17+
# [START Dockerfile]
18+
FROM apache/airflow:2.5.0.dev0
19+
COPY requirements.txt /
20+
RUN pip install --no-cache-dir -r /requirements.txt
21+
# [END Dockerfile]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lxml
2+
beautifulsoup4

0 commit comments

Comments
 (0)