【发布时间】:2020-07-27 20:55:55
【问题描述】:
我构建了一个安装了 crontab 的 python docker 映像。我想安排一份工作。 crontab 正在运行:
/etc/init.d/cron status
[ ok ] cron is running.
并且已经配置好了:
crontab -l
*/30 * * * * root /web/sync_html.sh >> /var/log/cron.log 2>&1
我什至为每分钟添加了一个“日期”命令调度:
* * * * * root date >> /var/log/cron.log
当我手动运行这些命令时,它可以工作。但调度不起作用。有什么想法吗?
编辑:Dockerfile:
FROM python:3
# Copy local files to container
COPY www /web
RUN chmod -R 777 /web
RUN pip3 install -r /web/requirments.txt
# install crontab
RUN apt-get update && apt-get install -y cron
# Add crontab file in the cron directory
ADD crontab /etc/cron.d/hello-cron
# Give execution rights on the cron job
RUN chmod 0644 /etc/cron.d/hello-cron
# Apply cron job
RUN crontab /etc/cron.d/hello-cron
# Create the log file to be able to run tail
RUN touch /var/log/cron.log
EXPOSE 8081
CMD [ "python", "/web/app.py", "-p", "8081" ]
【问题讨论】:
-
更好地展示你的 Dockerfile,cron 进程是否在
cmd开始? -
@Adiii 已添加 :)
标签: python linux bash docker cron