You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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表明数据库迁移表中存在冲突的版本记录,需手动清理:

  1. 进入运行中的Postgres容器(替换<postgres-container-name>为你的容器名,可通过docker ps查看):
    docker exec -it <postgres-container-name> bash
    
  2. 连接Airflow数据库:
    psql -U airflow airflow
    
  3. 查询当前迁移版本:
    SELECT version_num FROM alembic_version;
    
  4. 删除冲突的版本记录(根据错误中的冲突版本,此处为13eb55f81627):
    DELETE FROM alembic_version WHERE version_num = '13eb55f81627';
    
  5. 输入\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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 22:50:23