docker容器中crontab时的Python日志记录



我正在运行一个python作业,该作业登录到一个文件:

logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', filename='/app/logs/ups_tracking.log')
self.logger = logging.getLogger('TRACK-UPS')

手动运行作业时,日志文件会很好地创建/增加新条目。

当运行crontab(下面的语法(时,日志并没有按预期写入。

### TRACKING UPS ###
* * * * * python /app/UPS/parcels.py
root@91067d2217e7:/app/logs# service cron status
[ ok ] cron is running.

我正在一个docker容器中运行整个过程,docker文件如下:

#Create the flask custom image
FROM python:latest

# Place your flask application on the server
COPY ./back /app/
WORKDIR /app
# Install requirements.txt
RUN /usr/local/bin/python -m pip install --upgrade pip 
RUN pip3 install --no-cache-dir -r requirements.txt
RUN apt-get update && apt-get install -y netcat cron
COPY ./config/init.sh /tmp/init.sh
RUN chmod +x /tmp/init.sh
# Copy crontab_file file to the cron.d directory
COPY ./config/crontab_file /etc/cron.d/crontab_file

# Give execution rights on the cron job
RUN chmod 0644 /etc/cron.d/crontab_file
# Apply cron job
RUN crontab /etc/cron.d/crontab_file
# Start CRON service
RUN service cron start
EXPOSE 8889
ENTRYPOINT ["/tmp/init.sh"]

我是不是遗漏了什么?

谢谢!

# Start CRON service
RUN service cron start

意味着crond仅在RUN阶段期间运行。

看到这里,我想知道你是否也在/tmp/init.sh中启动cron?

最新更新