This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 899ce98b5c2 Add docker stack docs example for venv scene (#69088)
899ce98b5c2 is described below
commit 899ce98b5c2730abeef19b15c840e537cd2b6227
Author: Andrew Chang <[email protected]>
AuthorDate: Mon Jun 29 04:38:29 2026 +0000
Add docker stack docs example for venv scene (#69088)
---
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..74bc8ac7bf7
--- /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.4.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