1. 크롬, 크롬브라우저 버전 맞추기 / 버전 고정
2. 파이썬 경로를 설정해주는 부분이 필요함
- * * * * * root /usr/local/bin/python3.9 /usr/src/app/main.py > /tmp/crawler.log 2>&1 과 같이 하면 파이썬 실행시 발생하는 에러로그들을 확인 할 수 있음. 파이썬 스크립트 내에 로그 라이브러리를 써도 import 과 같은 에러는 실행이 완료 되기 전에 발생하는 에러들로, 이러한 에러 + 전체 로그들을 볼 수 있음
- cron 파일은 마지막줄에 한줄 남겨줘야함 안그러면 에러뜸
# install chrome, chrome driver
ENV CHROMEDRIVER_DIR="/usr/local/bin"
ENV CHROMEDRIVER_VERSION="88.0.4324.96"
ENV CHROME="google-chrome-stable_$CHROMEDRIVER_VERSION-1_amd64.deb"
RUN apt-get install -y wget unzip
RUN wget http://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/$CHROME
RUN apt-get install -y ./$CHROME
RUN wget -q --continue -P $CHROMEDRIVER_DIR "http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip"
RUN unzip $CHROMEDRIVER_DIR/chromedriver* -d $CHROMEDRIVER_DIR
# cronjob
# crontab sys log $busybox readlog
# cronjob log $tail -f /tmp/crawler.log
USER root
RUN apt-get install -y cron busybox locales
COPY crontab /etc/cron.d/crontab
RUN touch /tmp/crawler.log
RUN chmod +x /etc/cron.d/crontab
RUN /usr/bin/crontab /etc/cron.d/crontab
# https://www.geeksforgeeks.org/cron-command-in-linux-with-examples/
# cron -L 2 => -L 2: log level
# cron -f => Used to stay in foreground mode, and don’t daemonize
# buuxybox syslogd => System logging utility.( -C => Log to shared mem buffer)
CMD busybox syslogd -C; cron -L 2 -f
#DOCKER_BUILDKIT=0 docker build --no-cache --progress=plain -t crawler .
docker build -t crawler(IMAGE) .
{
docker rm -f crawler(CONTAINER)
}
docker run -d --name crawler(CONTAINER) -v logs:/usr/src/app/logs crawler(IMAGE)