0

我有一个 dockerfile 可以自动构建图像。

我正在使用 docker cloud,连接到 Digital Ocean 作为服务器。

在我的 dockerfile 中,我得到了我需要的软件,添加了包含python我希望运行的脚本的相关 GitHub 存储库。然后我启动 cron 调度程序并添加适当时间的脚本。例如: cron_files.txt 文件如下所示:

0 12 * * * /usr/bin/python /home/dir/run_check.py

0 15 * * * /usr/bin/python /home/dir/run_push.py

在我的 dockerfile 中,我执行以下操作:

RUN service cron start
RUN service cron status
RUN crontab -u root cron_files.txt

在日志文件中,我可以看到 cron 已成功启动。

编辑,感谢 r0manarmy - How to run a cron job inside a docker container?

# 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

# Create the log file to be able to run tail
RUN touch /var/log/cron.log

# Run the command on container startup
CMD cron && tail -f /var/log/cron.log

如何编辑上面的内容以从而cron_files.txt不是上面的示例创建 crontab 文件?

我试过了ADD crontab cron_files.txt /etc/cron.d/feeds

但这会返回:

ADD crontab cron_files.txt /etc/cron.d/feeds
lstat crontab: no such file or directory

附言。我在用FROM debian:jessie

4

1 回答 1

0

您可能希望将 cron 设置为CMD

为此,只需crond在 alpine linux 上使用该命令。

看看这个例子的想法:

https://gist.github.com/mhubig/a01276e17496e9fd6648cf426d9ceeec

于 2016-11-21T13:49:23.277 回答