FROM python:3.9.2-buster
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
RUN apt-get update && apt-get install -y --no-install-recommends \
vim \
cron \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY requirements.txt .
RUN pip install --upgrade pip && pip install --no-cache-dir -r requirements.txt
COPY app/ .
COPY crontab /etc/cron.d/crontab
COPY rebonz.py /app/rebonz.py
RUN chmod 0744 /etc/cron.d/crontab
RUN /usr/bin/crontab /etc/cron.d/crontab
# run crond as main process of container
CMD ["cron", "-f"]
#run python script every 4 hours
0 */4 * * * /usr/local/bin/python /app/my_script.py > /proc/1/fd/1 2>/proc/1/fd/2
Python import error with cronjob in a docker container
# crontab 스크립트
#run python script every 4 hours
0 */4 * * * python /app/my_script.py > /proc/1/fd/1 2>/proc/1/fd/2
# crontab 스크립트
#run python script every 4 hours
0 */4 * * * /usr/local/bin/python /app/my_script.py > /proc/1/fd/1 2>/proc/1/fd/2
감사합니다!