🌊 Docker-Compose로 Airflow 구성하기
- Docker를 사용하여 Airflow를 구성하려면 airflow-webserver, airflow-scheduler, airflow-triggerer, airflow-worker, postgres, redis의 최소 6개의 컨테이너를 직접 설정해주어야 한다.
- Docker Compose를 사용하면 docker-compose.yaml에 필요한 컨테이너에 대해 설정해주면 Airflow를 쉽게 구성할 수 있다.
- Apache 공식 사이트에서 제공하는 docker-compose 설정을 사용하여 구성해보자.
sudo yum -y update
sudo yum install -y gcc openssl-devel bzip2-devel libffi-devel
wget https://www.python.org/ftp/python/3.9.5/Python-3.9.5.tgz
tar -xvf Python-3.9.5.tgz
rm Python-3.9.5.tgz
cd Python-3.9.5/
./configure --enable-optimizations
sudo make altinstall
cd ..
sudo yum install -y python3-pip python3-devel gcc gcc-c++ libffi-devel openssl-devel python3-setuptools
sudo pip3 install -y pymysql
sudo pip3 install -y virtualenv
virtualenv -p python3.9 airflow-docker-env
source airflow-docker-env/bin/activate
sudo yum -y update
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
version='23.0.1'
sudo yum install -y docker-ce-${version} docker-ce-cli-${version} containerd.io docker-buildx-plugin docker-compose-plugin
sudo systemctl start docker
sudo systemctl enable docker
sudo systemctl enable docker.service
sudo systemctl enable containerd.service
sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker
docker image pull centos:7
sudo yum -y update
sudo yum install -y docker-compose-plugin
curl -LfO 'https://airflow.apache.org/docs/apache-airflow/2.5.1/docker-compose.yaml'
sed -i 's/^ volumes:/ volumes:\n \- ${AIRFLOW_PROJ_DIR:-.}\/codes:\/opt\/airflow\/codes/1' docker-compose.yaml
mkdir -p ./dags ./logs ./plugins ./codes
echo -e "AIRFLOW_UID=$(id -u)\nAIRFLOW_GID=0" > .env
docker compose up airflow-init
docker compose up
🐳 도커 상태 확인
- docker-compose.yaml에 설정된 것 처럼 총 6개의 컨테이너가 잘 실행된 것을 볼 수 있음
참고 링크