This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch v3-3-test
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/v3-3-test by this push:
new 72e765fca9a [v3-3-test] Add docker stack docs example for venv scene
(#69088) (#69112)
72e765fca9a is described below
commit 72e765fca9a7978bc469737e2519bce4dd0f4ca2
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Fri Jul 3 16:03:07 2026 +0200
[v3-3-test] Add docker stack docs example for venv scene (#69088) (#69112)
* [v3-3-test] Add docker stack docs example for venv scene (#69088)
(cherry picked from commit 899ce98b5c2730abeef19b15c840e537cd2b6227)
Co-authored-by: Andrew Chang <[email protected]>
* Use 3.3.0 base image in the venv Dockerfile example on v3-3-test
The example was backported verbatim from main, where the base image is
apache/airflow:3.4.0. On the v3-3-test branch the example should reference
the
matching release line, 3.3.0.
---------
Co-authored-by: Andrew Chang <[email protected]>
Co-authored-by: Jarek Potiuk <[email protected]>
---
docker-stack-docs/build.rst | 22 ++++++++++++++++++++
.../extending/add-python-venv/Dockerfile | 24 ++++++++++++++++++++++
.../extending/add-python-venv/requirements.txt | 1 +
3 files changed, 47 insertions(+)
diff --git a/docker-stack-docs/build.rst b/docker-stack-docs/build.rst
index dd3cf7e01f7..79ffe2bd7b2 100644
--- a/docker-stack-docs/build.rst
+++ b/docker-stack-docs/build.rst
@@ -477,6 +477,28 @@ Note that similarly when adding individual packages, you
need to use the ``airfl
:language: text
+Example of adding a Python venv for ``ExternalPythonOperator``
+..............................................................
+
+The following example creates a separate Python virtualenv inside the image
and installs packages
+from ``requirements.txt`` into it, leaving Airflow's own Python environment
untouched. This is the
+typical setup for the
+:ref:`ExternalPythonOperator
<apache-airflow-providers-standard:howto/operator:externalpythonoperator>`
+(or the ``@task.external_python`` decorator), which executes tasks in a
pre-existing, immutable
+Python environment. Use ``/opt/airflow/venv/bin/python`` as the operator's
``python`` argument
+to run tasks in this venv.
+
+The venv is created without ``--system-site-packages``, so the packages
installed inside it
+are isolated from Airflow's own dependencies.
+
+.. exampleinclude:: docker-examples/extending/add-python-venv/Dockerfile
+ :language: Dockerfile
+ :start-after: [START Dockerfile]
+ :end-before: [END Dockerfile]
+
+.. exampleinclude:: docker-examples/extending/add-python-venv/requirements.txt
+ :language: text
+
Example when writable directory is needed
.........................................
diff --git
a/docker-stack-docs/docker-examples/extending/add-python-venv/Dockerfile
b/docker-stack-docs/docker-examples/extending/add-python-venv/Dockerfile
new file mode 100644
index 00000000000..13fe643797f
--- /dev/null
+++ b/docker-stack-docs/docker-examples/extending/add-python-venv/Dockerfile
@@ -0,0 +1,24 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# This is an example Dockerfile. It is not intended for PRODUCTION use
+# [START Dockerfile]
+FROM apache/airflow:3.3.0
+COPY requirements.txt /
+RUN python -m venv /opt/airflow/venv \
+ && /opt/airflow/venv/bin/pip install --no-cache-dir -r /requirements.txt
+# [END Dockerfile]
diff --git
a/docker-stack-docs/docker-examples/extending/add-python-venv/requirements.txt
b/docker-stack-docs/docker-examples/extending/add-python-venv/requirements.txt
new file mode 100644
index 00000000000..e8710b5a474
--- /dev/null
+++
b/docker-stack-docs/docker-examples/extending/add-python-venv/requirements.txt
@@ -0,0 +1 @@
+colorama==0.4.0