【发布时间】:2019-11-05 22:24:16
【问题描述】:
我正在尝试在 docker 中使用 cron 运行我的两个 python 文件。 我有两个文件 a.py 和 b.py,它们将使用 cron 和它们之间的特定时间段运行。
如何通过 docker 解决这个问题?
【问题讨论】:
我正在尝试在 docker 中使用 cron 运行我的两个 python 文件。 我有两个文件 a.py 和 b.py,它们将使用 cron 和它们之间的特定时间段运行。
如何通过 docker 解决这个问题?
【问题讨论】:
这是我正在使用的。你可以参考
FROM ubuntu:latest
# Install cron
RUN apt-get update
RUN apt-get install cron
RUN apt-get install -y python3
RUN apt-get install -y python3-pip
# Add crontab file in the cron directory
ADD crontab /etc/cron.d/simple-cron
# Add shell script and grant execution rights
ADD dir/ /
ADD requirements.txt /
ADD script.sh /script.sh
WORKDIR /
RUN pip3 install -r requirements.txt
RUN chmod +x /script.sh
# Give execution rights on the cron job
RUN chmod 0644 /etc/cron.d/simple-cron
# Create the log file to be able to run tail
RUN touch /var/log/cron.log
# Run the command on container startup
CMD printenv | sed 's/^\(.*\)$/export \1/g' > /env.sh && cron && tail -f /var/log/cron.log
【讨论】: