【发布时间】:2019-10-13 22:41:26
【问题描述】:
我在尝试创建一个运行 cronjob 的容器时遇到了一些问题。我可以看到 cron 在容器中使用 top 运行,但它不会像下面的示例尝试那样写入日志文件。该文件保持为空。
我在这里阅读了相同问题的答案:
- How to run a cron job inside a docker container?
- Output of `tail -f` at the end of a docker CMD is not showing
但我无法让任何建议发挥作用。例如,我使用了这里的 dockerfile:https://github.com/Ekito/docker-cron/
FROM ubuntu:latest
MAINTAINER docker@ekito.fr
# 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
#Install Cron
RUN apt-get update
RUN apt-get -y install cron
# Run the command on container startup
CMD cron && tail -f /var/log/cron.log
crontab:
* * * * * root echo "Hello world" >> /var/log/cron.log 2>&1
# Don't remove the empty line at the end of this file. It is required to run the cron job
它在我的机器上不起作用(Windows 10)。显然,其他人似乎也报告了一个特定于 Windows 的问题:https://github.com/Ekito/docker-cron/issues/3
为了测试是否只是我做错了什么,我尝试在运行 ubuntu 的虚拟机中做同样的事情(所以是一个 ubuntu 主机而不是我的 windows 主机)并且按预期工作。日志文件按预期扩展。
那么我可以做些什么来尝试完成这项工作?
我尝试写入已安装(绑定)的文件夹并创建要写入的卷。都没有用。
【问题讨论】:
标签: docker cron dockerfile docker-for-windows