0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Airflow 3.0 を最小構成で起動して UI に入るまで(dbt×BigQuery前提/Docker Compose)

Last updated at Posted at 2025-09-11

前書き

GPTと会話履歴を備忘録に残しました。
色々と参考にしましたが、うまくできず、バージョン古い等や自分の理解力不足で回り道しました。
自分のPCがメモリ8GBなのでそれに合わせる形の最小構成にしました。

結論

  • Airflow 3.0 では airflow webserver が廃止airflow api-server に統合。
  • 最小構成は postgres + scheduler + api-server(UI) の3つ。
    追記→Airflow 3 では “DAG を UI に出す役=DAG Processor”を追加して4つ
  • 8080が繋がらない時は、たいてい webserver コマンド名が古いのが原因。

検証環境

  • Docker Desktop (RAM 2GBでも可、推奨4GB)
  • Apache Airflow 3.0.6(公式イメージ)
  • PostgreSQL 13
  • 目標:dbt-core + dbt-bigquery を後載せ

起動用 docker-compose(最小)

# docker-compose.yml
x-airflow-common: &airflow-common
  image: apache/airflow:3.0.6
  environment: &airflow-common-env
    AIRFLOW__CORE__EXECUTOR: SequentialExecutor
    AIRFLOW__DATABASE__SQL_ALCHEMY_CONN: postgresql+psycopg2://airflow:airflow@postgres/airflow
    # Fernetキーは自分で生成して差し替え
    AIRFLOW__CORE__FERNET_KEY: "YOUR _KEY"
    AIRFLOW__CORE__DAGS_ARE_PAUSED_AT_CREATION: "true"
    AIRFLOW__CORE__LOAD_EXAMPLES: "false"
    AIRFLOW__SCHEDULER__ENABLE_HEALTH_CHECK: "true"
    # 3.0ではAPIセクションに移動したが、互換で動く
    AIRFLOW__WEBSERVER__WEB_SERVER_HOST: "0.0.0.0"
    AIRFLOW__WEBSERVER__WEB_SERVER_PORT: "8080"
    AIRFLOW__WEBSERVER__WORKERS: "1"
    AIRFLOW__WEBSERVER__WORKER_CLASS: "sync"
    AIRFLOW_CONFIG: "/opt/airflow/config/airflow.cfg"
  volumes:
    - ./dags:/opt/airflow/dags
    - ./logs:/opt/airflow/logs
    - ./config:/opt/airflow/config
    - ./plugins:/opt/airflow/plugins
  user: "${AIRFLOW_UID:-50000}:0"
  depends_on:
    postgres:
      condition: service_healthy

services:
  postgres:
    image: postgres:13
    environment:
      POSTGRES_USER: airflow
      POSTGRES_PASSWORD: airflow
      POSTGRES_DB: airflow
    volumes:
      - postgres-db-volume:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD", "pg_isready", "-U", "airflow"]
      interval: 10s
      retries: 5
      start_period: 5s
    restart: always

  # UI(Airflow 3.0は api-server がUIも提供)
  airflow-webserver:
    <<: *airflow-common
    command: api-server
    ports:
      - "8080:8080"
    healthcheck:
      test: ["CMD", "curl", "--fail", "http://localhost:8080/api/v2/version"]
      interval: 30s
      timeout: 10s
      retries: 5
      start_period: 30s
    restart: always
    depends_on:
      postgres:
        condition: service_healthy
      airflow-init:
        condition: service_completed_successfully

  # スケジューラ(軽量設定)
  airflow-scheduler:
    <<: *airflow-common
    command: scheduler
    healthcheck:
      test: ["CMD", "curl", "--fail", "http://localhost:8974/health"]
      interval: 30s
      timeout: 10s
      retries: 5
      start_period: 30s
    restart: always
    depends_on:
      postgres:
        condition: service_healthy
      airflow-init:
        condition: service_completed_successfully

  # 初期化(DBマイグレーション & 管理ユーザー作成)
  airflow-init:
    <<: *airflow-common
    entrypoint: /bin/bash
    user: "0:0"
    command:
      - -c
      - |
        set -e
        mkdir -p /opt/airflow/{logs,dags,plugins,config}
        /entrypoint airflow db upgrade
        /entrypoint airflow users create \
          --username airflow --firstname Air --lastname Flow \
          --role Admin --email admin@example.com --password airflow || true
        chown -R "${AIRFLOW_UID:-50000}:0" /opt/airflow
        echo "Init done"

volumes:
  postgres-db-volume:

Fernetキーの作り方(1行)

python3 - <<'PY'
from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())
PY

起動〜UIログイン

docker compose up airflow-init
docker compose up -d

image.png

参考サイト

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?