docker airflow extend

이상민·2023년 5월 3일
0

airflow

목록 보기
3/3

오류

Docker를 통해 Airflow를 실행할 때 Import Error: no module named 'oauth2client'라는 오류가 발생한다. ubuntu에 sudo pip3 install oauth2client로 oauth2client 모듈을 설치해도 오류는 고쳐지지 않는다.

원인

각 버전의 airflow reference image는 고정된 상태로 존재한다. 이는 설정된 특정 모듈만이 설치가 가능하며 oauth2client의 경우 reference image에 존재하지 않는 모듈이므로 ubuntu내에서 설치하더라도 airflow에 영향을 주지 않는다.

해결

extend와 customizing 2가지 방법이 존재한다. 나는 extend로 해결이 되었다. 그래서 customizing은 없다
공식 문서

extend

file 생성 및 수정

$ ls
Dockerfile  dags  data-engineering-batch12  docker-compose.yaml  logs  plugins  requirements.txt

airflow 공식 문서에서 설치를 진행했다면 dags, docker-compose.yaml, logs, plugins 이렇게 1가지 파일과 3가지 디렉토리가 생성되었을 것이다. 이 디렉토리에 먼저 requirements.txt를 생성한다.

$ vi requirements

oauth2client==4.1.3
gspread
# 버전 지정은 자유

import error가 발생한 모듈을 지정한다. 이후 Dockerfile을 생성한다.

$ vi Dockerfile

FROM apache/airflow:2.6.0
COPY requirements.txt /
RUN pip install --no-cache-dir -r /requirements.txt

마지막으로 docker-compose.yaml을 수정하는데 이때 사용하는 image인 extend_airflow:latest는 파일 수정 이후 build할 이미지이다.

$ vi docker-compose.yaml

...
image: ${AIRFLOW_IMAGE_NAME:-extend_airflow:latest}
...

docker 실행

$ docker build . --tag extend_airflow:latest
$ docker compose up -d

extend_airflow:latest로 이미지를 빌드하고 실행한다.

0개의 댓글

Powered by GraphCDN, the GraphQL CDN