我正在尝试在docker中使用cron运行我的两个python文件。 我有两个文件a.py和b.py,它们将以cron以及它们之间的特定时间段运行。
如何通过docker处理这个问题?
答案 0 :(得分:0)
请检查此链接。还有一个类似的问题。
答案 1 :(得分:0)
这是我正在使用的。您可以参考
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