I'm trying to build a container to run my airflow using only dockerfile (not docker-compose). Here is my dockerfile. I'm running this on a server linux machine I succesfully managed to build the image, but when I run, it would immediately exit and output the error:
File "/usr/local/lib/python3.10/site-packages/airflow/www/session.py", line 21, in <module> from flask_session.sessions import SqlAlchemySessionInterface ModuleNotFoundError: No module named 'flask_session.sessions'
Even though I have specified my dockerfile to install Flask-Session.
Here is my dockerfile:
FROM python:3.10.13-slim-bullseye
ENV DEBIAN_FRONTEND noninteractive
ENV TERM linux
# Airflow
ARG AIRFLOW_VERSION=2.7.3
ARG AIRFLOW_DEPS=""
ARG PYTHON_DEPS=""
ENV AIRFLOW_HOME=/usr/local/airflow
# Define en_US.
ENV LANGUAGE en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LC_ALL en_US.UTF-8
ENV LC_CTYPE en_US.UTF-8
ENV LC_MESSAGES en_US.UTF-8
ENV AIRFLOW__CORE__EXECUTOR LocalExecutor
RUN set -ex \
&& buildDeps=' \
freetds-dev \
libkrb5-dev \
libsasl2-dev \
libssl-dev \
libffi-dev \
libpq-dev \
' \
&& apt-get update -yqq \
&& apt-get upgrade -yqq \
&& apt-get install -yqq --no-install-recommends \
$buildDeps \
freetds-bin \
build-essential \
default-libmysqlclient-dev \
unixodbc-dev \
apt-utils \
curl \
rsync \
netcat \
locales \
sudo \
git \
krb5-user \
openssh-client \
&& apt-get install gnupg2 apt-transport-https curl -y \
&& curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
&& curl https://packages.microsoft.com/config/debian/11/prod.list > /etc/apt/sources.list.d/mssql-release.list \
&& apt-get update \
&& ACCEPT_EULA=Y apt-get install msodbcsql17 -y \
&& ACCEPT_EULA=Y apt-get install mssql-tools -y \
&& echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc \
&& sed -i 's/^# en_US.UTF-8 UTF-8$/en_US.UTF-8 UTF-8/g' /etc/locale.gen \
&& locale-gen \
&& update-locale LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 \
&& useradd -ms /bin/bash -d /usr/local/airflow airflow \
&& pip install -U pip setuptools wheel \
&& pip install 'SQLAlchemy==1.3.23' \
&& pip install 'Flask-SQLAlchemy==2.4.4' \
&& pip install pytz \
&& pip install pyOpenSSL \
&& pip install ndg-httpsclient \
&& pip install pyasn1 \
&& pip install openpyxl \
&& pip install pyodbc \
&& pip install pysmb \
&& pip install twilio \
&& pip install oauth2client \
&& pip install googleads \
&& pip install twitter_ads \
&& pip install google-api-python-client \
&& pip install virtualenv \
&& pip install 'werkzeug<1.0.0' \
&& pip install 'email-validator' \
&& pip install "apache-airflow[crypto,celery,hive,jdbc,ssh]==2.7.3" \
&& pip install 'redis==3.2' \
&& pip install 'Flask-Session' \
&& pip install facebook_business \
&& if [ -n "${PYTHON_DEPS}" ]; then pip install ${PYTHON_DEPS}; fi \
&& apt-get purge --auto-remove -yqq $buildDeps \
&& apt-get autoremove -yqq --purge \
&& apt-get clean \
&& rm -rf \
/var/lib/apt/lists/* \
/tmp/* \
/var/tmp/* \
/usr/share/man \
/usr/share/doc \
/usr/share/doc-base
And here is the logs with the error when I tried to build and run the container:
[2025-06-03T21:20:11.780+0000] {{configuration.py:2049}} INFO - Creating new FAB webserver config file in: /usr/local/airflow/webserver_config.py
/usr/local/lib/python3.10/site-packages/airflow/models/base.py:71 DeprecationWarning: The sql_alchemy_conn option in [core] has been moved to the sql_alchemy_conn option in [database] - the old setting has been used, but please update your config.
/usr/local/lib/python3.10/site-packages/airflow/models/abstractoperator.py:61 DeprecationWarning: The default_queue option in [celery] has been moved to the default_queue option in [operators] - the old setting has been used, but please update your config.
/usr/local/lib/python3.10/site-packages/airflow/models/dag.py:445 DeprecationWarning: The dag_concurrency option in [core] has been renamed to max_active_tasks_per_dag - the old setting has been used, but please update your config.
/usr/local/lib/python3.10/site-packages/airflow/models/dag.py:3753 DeprecationWarning: The dag_concurrency option in [core] has been renamed to max_active_tasks_per_dag - the old setting has been used, but please update your config.
Traceback (most recent call last):
File "/usr/local/bin/airflow", line 8, in <module>
sys.exit(main())
File "/usr/local/lib/python3.10/site-packages/airflow/__main__.py", line 57, in main
args.func(args)
File "/usr/local/lib/python3.10/site-packages/airflow/cli/cli_config.py", line 49, in command
return func(*args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/airflow/utils/cli.py", line 112, in wrapper
check_and_run_migrations()
File "/usr/local/lib/python3.10/site-packages/airflow/utils/db.py", line 829, in check_and_run_migrations
source_heads = set(env.script.get_heads())
File "/usr/local/lib/python3.10/site-packages/alembic/script/base.py", line 379, in get_heads
return list(self.revision_map.heads)
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 1113, in __get__
obj.__dict__[self.__name__] = result = self.fget(obj)
File "/usr/local/lib/python3.10/site-packages/alembic/script/revision.py", line 155, in heads
self._revision_map
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 1113, in __get__
obj.__dict__[self.__name__] = result = self.fget(obj)
File "/usr/local/lib/python3.10/site-packages/alembic/script/revision.py", line 209, in _revision_map
for revision in self._generator():
File "/usr/local/lib/python3.10/site-packages/alembic/script/base.py", line 159, in _load_revisions
script = Script._from_path(self, real_path)
File "/usr/local/lib/python3.10/site-packages/alembic/script/base.py", line 1035, in _from_path
module = util.load_python_file(dir_, filename)
File "/usr/local/lib/python3.10/site-packages/alembic/util/pyfiles.py", line 114, in load_python_file
module = load_module_py(module_id, path)
File "/usr/local/lib/python3.10/site-packages/alembic/util/pyfiles.py", line 134, in load_module_py
spec.loader.exec_module(module) # type: ignore
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/usr/local/lib/python3.10/site-packages/airflow/migrations/versions/0074_2_0_0_resource_based_permissions.py", line 30, in <module>
from airflow.www.app import cached_app
File "/usr/local/lib/python3.10/site-packages/airflow/www/app.py", line 49, in <module>
from airflow.www.extensions.init_session import init_airflow_session_interface
File "/usr/local/lib/python3.10/site-packages/airflow/www/extensions/init_session.py", line 23, in <module>
from airflow.www.session import AirflowDatabaseSessionInterface, AirflowSecureCookieSessionInterface
File "/usr/local/lib/python3.10/site-packages/airflow/www/session.py", line 21, in <module>
from flask_session.sessions import SqlAlchemySessionInterface
ModuleNotFoundError: No module named 'flask_session.sessions'
What do you think I should do to tackle this?
Turns out, it's because of new version of flask-session is not compatible with the old version of airflow. I limited my flask-session < 0.6 and it works just fine!