【发布时间】:2016-02-12 10:31:34
【问题描述】:
我尝试设置 cron 以在我的 Docker 容器中运行,但到目前为止没有成功。
这是Dockerfile的cron相关部分:
FROM ruby:2.2.2
# Add crontab file in the cron directory
RUN apt-get install -y rsyslog
ADD crontab /etc/cron.d/hello-cron
# Give execution rights on the cron job
RUN chmod +x /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
RUN service cron start
当我登录到容器实例时,cron 似乎正在运行:
$ service cron status
cron is running.
/etc/cron.d 有我的工作:
$ cat /etc/cron.d/hello-cron
* * * * * root echo "Hello world" >> /var/log/cron.log 2>&1
但是/var/log/cron.log 没有附加任何内容,因此它似乎没有运行。
然后,如果我在容器内运行 $ cron,它会注册我的 hello-cron 文件,并且日志文件每分钟都会附加“Hello world”。
【问题讨论】: