본문 바로가기
글쓰기 및 블로그

N2T(Notion2Tistory) 사용법(3) - using docker

by nineking 2023. 1. 18.

Reference

Environment

  • OS : ubuntu 22.04
  • Docker version 20.10.22, build 3a2c30b
  • working directory : ~/work/docker-n2t
  • config.py 파일 미리 준비

Abstract

일반적인 리눅스/PC 환경과 달리, container 환경에서 pip를 사용하여 selenium 설치 및 사용하면 chromedriver 에러가 발생한다.

따라서 container 환경에 최적화된 selenium 구동이 필요하였고, 직접 docker image를 build 하여 이를 해결하였다.

N2T 패키지 또한 container라는 특수한 환경때문에 selenium 구동 코드에서 추가적인 옵션을 적용해주었다.

Contents

  1. N2T 준비
  1. Docker image 만들기
  1. Docker image 업로드

N2T 준비

  1. git clone
git clone https://github.com/jmjeon94/N2T.git
  1. config.py 백업
mv ./N2T/config.py ./N2T/config.py.sample
  1. SeleniumClient.py 수정
docker container 환경에서 실행하면 Message: unknown error: session deleted because of page crash 에러가 발생한다. selenium chrome option에 /deb/shm 디렉토리를 사용하지 않는다는 의미의 --disable-dev-shm-usage 옵션 추가 필요
vi ./N2T/clients/SeleniumClient.py

18라인에 다음 옵션 추가

options.add_argument('--disable-dev-shm-usage')

Docker image 만들기

Dockerfile 작성

vi Dockerfile
FROM python:3.9
WORKDIR /usr/src
RUN sed -i 's|deb.debian.org|ftp.kaist.ac.kr|g' /etc/apt/sources.list
RUN apt-get -y update
RUN apt install wget
RUN apt install unzip  
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN apt -y install ./google-chrome-stable_current_amd64.deb
RUN wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/` curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.zip
RUN mkdir chrome
RUN unzip /tmp/chromedriver.zip chromedriver -d /usr/src/chrome
COPY N2T ./app
RUN pip install --no-cache-dir -r ./app/requirements.txt
CMD [ "python", "app/main.py" ]

Docker Image build

build를 마치면 docker hub에 업로드할 예정이기 때문에 계정(nineking424)을 포함한 image tag 이름을 생성해준다.

docker build --tag nineking424/docker-n2t .

Successfully … 메세지가 확인되면 성공

Docker Image test

발행할 페이지 준비

컨테이너 실행

  • —rm : 컨테이너 종료 후 삭제
  • -v : 컨테이너 실행 시 파일 mount
docker run --rm -v $(pwd)/config.py:/usr/src/app/config.py -it nineking424/docker-n2t

블로그 확인

Docker image 업로드

docker login # Username에 email 전체가 아니라 '@' 앞부분만 적어야 정상 로그인 됨
docker push nineking424/docker-n2t

docker hub 업로드 확인

Trouble Shooting

Trouble Shooting 1 : selenium 설치가 제대로 안되었다.
Trouble Shooting2 : selenium 옵션 적용이 제대로 안되었다.


Uploaded by N2T