【问题标题】:Crontab running but not scheduling on dockercrontab 正在运行但未在 docker 上调度
【发布时间】: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


【解决方案1】:

您没有启动cron 进程。将 CMD 更改为低于 1,但请记住它会在后台启动 cron

CMD ["sh","-c","/etc/init.d/cron start && python /web/app.py -p 8081"]

【讨论】:

  • 我试过了,它也不起作用,反正 cron 进程已经启动,因为 - /etc/init.d/cron status [ ok ] cron 正在运行。
  • 当我在 cron 配置中添加换行符 (\n) 时,它终于起作用了,toda!
猜你喜欢
  • 1970-01-01
  • 2021-04-26
  • 1970-01-01
  • 2019-12-14
  • 2016-11-26
  • 2023-01-22
  • 2018-09-05
  • 1970-01-01
  • 2020-02-23
相关资源
最近更新 更多