【发布时间】:2018-09-05 16:38:40
【问题描述】:
我运行一个 docker php 容器来显示一个网站。我正在使用 php:5.6-apache 图像,然后在 Dockerfile 中我把这些行:
# Setup crontab
ADD ./crontab /etc/cron.d/crontab
RUN chmod 0644 /etc/cron.d/crontab
RUN touch /var/log/cron.log
CMD cron && tail -f /var/log/cron.log
这很好用,如果我在 crontab 文件中放入一行来将 hello world 放入文件中,则该过程有效,但我无法再访问我的网站。 如果我尝试写 localhost,我会收到“无法访问服务器错误”,就像没有服务器在运行一样。
如果我评论“CMD cron && tail -f /var/log/cron.log”,那么我现在可以访问服务器,但 crontab 不再工作......
我能做什么?
【问题讨论】:
-
是的,因为您已经覆盖了 CMD 入口点。你不能只使用
RUN和cron吗? -
RUNjustcronas @JonStirling 说,如果您需要查看日志,您可以稍后与docker exec -itd ContainerID /bin/bash联系并随意执行您的tails... -
谢谢它运作良好:)