docker-compose
를 이용해 Airflow를 운영하는데 필요한 여러 서비스(컨테이너)를 실행
https://airflow.apache.org/docs/apache-airflow/stable/howto/docker-compose/index.html
% curl -LfO 'https://airflow.apache.org/docs/apache-airflow/3.0.1/docker-compose.yaml'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 12766 100 12766 0 0 38365 0 --:--:-- --:--:-- --:--:-- 38336
docker-compose.yaml
경로를 복사해 터미널에서 요청docker-compose.yaml
파일을 보면 아래와 같은 컨테이너가 설치될 것임을 짐작 가능services:
postgres:
image: postgres:13
redis:
image: redis:7.2-bookworm
airflow-apiserver: ...
airflow-scheduler: ...
airflow-dag-processor: ...
airflow-worker: ...
airflow-triggerer: ...
airflow-init: ...
airflow-cli: ...
flower: ...
mkdir -p ./dags ./logs ./plugins ./config
echo -e "AIRFLOW_UID=$(id -u)" > .env
.env
파일을 생성docker compose up airflow-init
exited with code 0
가 출력되면 정상적으로 초기화되어 다음 단계로 진행docker compose up
docker ps
명령어를 입력해 컨테이너 실행 상태를 조회 가능% docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a0431bfa0d1f apache/airflow:3.0.1 "/usr/bin/dumb-init …" 1 minutes ago Up 1 minutes (healthy) 8080/tcp airflow-airflow-worker-1
4d32f0c45d4a apache/airflow:3.0.1 "/usr/bin/dumb-init …" 1 minutes ago Up 1 minutes (healthy) 8080/tcp airflow-airflow-triggerer-1
f4cd1b0887de apache/airflow:3.0.1 "/usr/bin/dumb-init …" 1 minutes ago Up 1 minutes (healthy) 8080/tcp airflow-airflow-dag-processor-1
3213192935b6 apache/airflow:3.0.1 "/usr/bin/dumb-init …" 1 minutes ago Up 1 minutes (healthy) 8080/tcp airflow-airflow-scheduler-1
e933dc415a73 apache/airflow:3.0.1 "/usr/bin/dumb-init …" 1 minutes ago Up 1 minutes (healthy) 0.0.0.0:8080->8080/tcp airflow-airflow-apiserver-1
94f88f2e5507 postgres:13 "docker-entrypoint.s…" 6 minutes ago Up 6 minutes (healthy) 5432/tcp airflow-postgres-1
3f82ba15433e redis:7.2-bookworm "docker-entrypoint.s…" 6 minutes ago Up 6 minutes (healthy) 6379/tcp airflow-redis-1
localhost:8080
주소로 접속하면 Airflow UI에 접근 가능airflow
입력tutorial_taskflow_templates
DAG를 클릭하여 상세 페이지 조회success
상태는 Task가 성공적으로 처리됨을 의미context
라는 객체를 출력하는 구문이 확인됨get_current_context()
라는 함수를 통해 context
라는 딕셔너리 객체를 가져와 출력하는 작업으로 추측[2025-05-27, 23:31:26] INFO - context: {'dag': <DAG: tutorial_taskflow_templates>, ...}: chan="stdout": source="task"
% docker compose stop
[+] Stopping 8/8
✔ Container airflow-airflow-dag-processor-1 Stopped 1.1s
✔ Container airflow-airflow-triggerer-1 Stopped 0.9s
✔ Container airflow-airflow-worker-1 Stopped 2.8s
✔ Container airflow-airflow-scheduler-1 Stopped 0.8s
✔ Container airflow-airflow-apiserver-1 Stopped 0.6s
✔ Container airflow-airflow-init-1 Stopped 0.0s
✔ Container airflow-postgres-1 Stopped 0.1s
✔ Container airflow-redis-1 Stopped 0.2s
docker-compose.yaml
파일이 있는 경로에서 서비스를 명시하지 않고 명령어를 실행하면 모든 Airflow 컨테이너를 중지% docker compose down --volumes --rmi all
[+] Running 13/13
✔ Container airflow-airflow-dag-processor-1 Removed 1.5s
✔ Container airflow-airflow-triggerer-1 Removed 1.2s
✔ Container airflow-airflow-worker-1 Removed 3.4s
✔ Container airflow-airflow-scheduler-1 Removed 1.0s
✔ Container airflow-airflow-apiserver-1 Removed 0.9s
✔ Container airflow-airflow-init-1 Removed 0.1s
✔ Container airflow-postgres-1 Removed 0.2s
✔ Container airflow-redis-1 Removed 0.2s
✔ Image apache/airflow:3.0.1 Removed 0.9s
✔ Image postgres:13 Removed 0.9s
✔ Image redis:7.2-bookworm Removed 0.9s
✔ Volume airflow_postgres-db-volume Removed 0.0s
✔ Network airflow_default Removed 0.5s
docker-compose.yaml
파일이 있는 경로에서 서비스를 명시하지 않고 명령어를 실행하면 모든 Airflow 컨테이너를 삭제--rmi
옵션을 추가하여 관련 이미지까지 모두 삭제