Docker部署Airflow时airflow-init-1容器启动失败求助
问题描述
本地Docker部署的Airflow曾运行正常,近期启动airflow-init-1容器后立即进入Exited状态,其他容器无异常。已尝试以下操作未解决:
- 执行
airflow db upgrade,提示zsh: command not found: airflow; - 检查
configuration.py,未发现错误提示中的旧配置; - 执行
pip uninstall airflow/pip3 uninstall airflow,提示WARNING: Skipping airflow as it is not installed。
容器错误日志:
2023-01-30 16:46:56 Postgres is up - executing command **2023-01-30 16:47:00 /home/airflow/.local/lib/python3.10/site-packages/airflow/configuration.py:538: 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. **2023-01-30 16:47:00 option = self._get_environment_variables(deprecated_key, deprecated_section, key, section) 2023-01-30 16:47:02 INFO [alembic.runtime.migration] Context impl PostgresqlImpl. 2023-01-30 16:47:02 INFO [alembic.runtime.migration] Will assume transactional DDL. 2023-01-30 16:47:04 Traceback (most recent call last): 2023-01-30 16:47:04 File "/home/airflow/.local/lib/python3.10/site-packages/alembic/script/base.py", line 233, in _catch_revision_errors 2023-01-30 16:47:00 2023-01-30 16:47:02 DB: postgresql+psycopg2://airflow:***@postgres/airflow 2023-01-30 16:47:04 raise util.CommandError(err.args[0]) from err 2023-01-30 16:47:04 alembic.util.exc.CommandError: Requested revision a13f7613ad25 overlaps with other requested revisions 13eb55f81627 2023-01-30 16:47:05 /home/airflow/.local/lib/python3.10/site-packages/airflow/configuration.py:538: 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. 2023-01-30 16:47:05 option = self._get_environment_variables(deprecated_key, deprecated_section, key, section) 2023-01-30 16:47:06 /home/airflow/.local/lib/python3.10/site-packages/airflow/configuration.py:538 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. 2023-01-30 16:47:07 ERROR: You need to upgrade the database. Please run `airflow db upgrade`. Make sure the command is run using Airflow version 2.3.4. 2023-01-30 16:47:08 /home/airflow/.local/lib/python3.10/site-packages/airflow/configuration.py:538: 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. 2023-01-30 16:47:08 option = self._get_environment_variables(deprecated_key, deprecated_section, key, section) 2023-01-30 16:47:08 2.3.4
解决方案
1. 修正配置文件(解决DeprecationWarning)
Docker部署的Airflow通常使用挂载的airflow.cfg文件或环境变量配置,而非直接修改configuration.py:
- 找到本地挂载的
airflow.cfg文件,将[core]section下的sql_alchemy_conn配置项移动到[database]section下; - 若使用环境变量,将
AIRFLOW__CORE__SQL_ALCHEMY_CONN替换为AIRFLOW__DATABASE__SQL_ALCHEMY_CONN,并更新docker-compose.yml或.env文件。
2. 解决Alembic迁移版本冲突
错误日志中的Requested revision a13f7613ad25 overlaps with other requested revisions 13eb55f81627表明数据库迁移表中存在冲突的版本记录,需手动清理:
- 进入运行中的Postgres容器(替换
<postgres-container-name>为你的容器名,可通过docker ps查看):docker exec -it <postgres-container-name> bash - 连接Airflow数据库:
psql -U airflow airflow - 查询当前迁移版本:
SELECT version_num FROM alembic_version; - 删除冲突的版本记录(根据错误中的冲突版本,此处为
13eb55f81627):DELETE FROM alembic_version WHERE version_num = '13eb55f81627'; - 输入
\q退出psql,再输入exit退出Postgres容器。
3. 在容器内执行数据库升级
你本地未安装Airflow,因此必须通过Docker容器执行airflow db upgrade命令:
- 若使用
docker-compose部署,执行:docker-compose run --rm airflow-init airflow db upgrade - 若直接用Docker镜像,执行(替换
<your-airflow-network>为你的Airflow网络名,$(pwd)/airflow为本地Airflow挂载目录):docker run --rm -v $(pwd)/airflow:/opt/airflow --network <your-airflow-network> apache/airflow:2.3.4 db upgrade
4. 重新启动Airflow容器
执行完上述步骤后,重新启动所有Airflow容器:
docker-compose down docker-compose up -d
内容的提问来源于stack exchange,提问作者hyunjin
相关产品推荐
相关产品推荐

