[Airflow] The "AIRFLOW_UID" variable is not set. Defaulting to a blank string. 에러 해결

docker compose up airflow-init 실행시 아래와 같은 에러 메시지 발생

WARN[0000] THE "AIRFLOW_UID" variable is not set. Defaulting to a blank string.

docker-compose.yaml 파일 내에서 환경 변수를 사용하는데, AIRFLOW_UID 변수가 설정되지 않았기 때문에 발생.

해결방법

mkdir -p ./dags ./logs ./plugins ./config
echo -e "AIRFLOW_UID=$(id -u)" > .env

 

이후 .env 에서 AIRFLOW_UID=501 와 같이 수동으로 Airflow_UID 지정해도 되고 

echo -e "AIRFLOW_UID=$(id -u)" > .env 명령어로 시스템상에 현재 UID 가져와서 지정

(base) cookie@airflow-setup % vim .env
(base) cookie@airflow-setup % mkdir -p ./dags ./logs ./plugins ./config
(base) cookie@airflow-setup % echo -e "AIRFLOW_UID=$(id -u)" > .env
(base) cookie@airflow-setup % cat .env
AIRFLOW_UID=501
(base) cookie@airflow-setup % docker compose up airflow-init
[+] Running 3/3
 ✔ Container airflow-setup-postgres-1      Created                                                                           0.5s 
 ✔ Container airflow-setup-redis-1         Created                                                                           0.4s 
 ✔ Container airflow-setup-airflow-init-1  Created                                                                           0.9s 
Attaching to airflow-init-1
airflow-init-1  | The container is run as root user. For security, consider using a regular user account.
airflow-init-1  | 
airflow-init-1  | DB: postgresql+psycopg2://airflow:***@postgres/airflow
airflow-init-1  | Performing upgrade to the metadata database postgresql+psycopg2://airflow:***@postgres/airflow
airflow-init-1  | [2024-11-21T09:21:31.494+0000] {migration.py:216} INFO - Context impl PostgresqlImpl.
airflow-init-1  | [2024-11-21T09:21:31.496+0000] {migration.py:219} INFO - Will assume transactional DDL.
airflow-init-1  | [2024-11-21T09:21:31.573+0000] {db.py:1623} INFO - Creating tables
airflow-init-1  | INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
airflow-init-1  | INFO  [alembic.runtime.migration] Will assume transactional DDL.
airflow-init-1  | Database migrating done!
airflow-init-1  | /home/airflow/.local/lib/python3.12/site-packages/flask_limiter/extension.py:337 UserWarning: Using the in-memory storage for tracking rate limits as no storage was explicitly specified. This is not recommended for production use. See: https://flask-limiter.readthedocs.io#configuring-a-storage-backend for documentation about configuring the storage backend.
airflow-init-1  | airflow already exist in the db
airflow-init-1  | 2.9.1
airflow-init-1 exited with code 0
(base) cookie@airflow-setup % docker compose -f docker-compose.yaml up
(base) cookie@airflow-setup % docker ps
CONTAINER ID   IMAGE                  COMMAND                   CREATED         STATUS                        PORTS                    NAMES
48754c3bc45e   apache/airflow:2.9.1   "/usr/bin/dumb-init …"   2 minutes ago   Up 2 minutes (healthy)        8080/tcp                 airflow-setup-airflow-worker-1
ef0536c9f21b   apache/airflow:2.9.1   "/usr/bin/dumb-init …"   2 minutes ago   Up 2 minutes (healthy)        8080/tcp                 airflow-setup-airflow-triggerer-1
69b2ff556f52   apache/airflow:2.9.1   "/usr/bin/dumb-init …"   2 minutes ago   Up About a minute (healthy)   0.0.0.0:8080->8080/tcp   airflow-setup-airflow-webserver-1
77f77390cb2a   apache/airflow:2.9.1   "/usr/bin/dumb-init …"   2 minutes ago   Up 2 minutes (healthy)        8080/tcp                 airflow-setup-airflow-scheduler-1
996bc6d06a24   postgres:13            "docker-entrypoint.s…"   3 minutes ago   Up 3 minutes (healthy)        5432/tcp                 airflow-setup-postgres-1
4bbb04676f00   redis:7.2-bookworm     "docker-entrypoint.s…"   3 minutes ago   Up 3 minutes (healthy)        6379/tcp                 airflow-setup-redis-1

 

 

참고

https://airflow.apache.org/docs/apache-airflow/stable/howto/docker-compose/index.html#docker-compose-env-variables

https://jhyunn.tistory.com/30