简体   繁体   English

从Docker堆栈运行cron作业的最佳实践

[英]Best practices to run cron job from a docker stack

here is the thing: I have a stack where a node js backend sends messages to a queue and perl workers (cron jobs) consume messages from that queue. 事情是这样的:我有一个堆栈,其中节点js后端将消息发送到队列,而perl worker(cron作业)使用该队列中的消息。 I already "dockerized" the node js backend but now I'm trying to do the same with the Perl Workers. 我已经“ dockerized”了节点js后端,但是现在我正尝试对Perl Workers执行相同的操作。

Already dockerized the Perl application itself however, as the "jobs" from the queue are consumed based on a crontab (ie every 2 mins) my question would be: 但是,已经在docker化了Perl应用程序本身,因为队列中的“作业”是基于crontab消耗的(即每2分钟),所以我的问题是:

What's the best way to accomplish this when having a stack built from a docker-compose file? 从docker-compose文件构建堆栈时,实现此目标的最佳方法是什么?

Let me know if I should provide more details. 让我知道是否需要提供更多详细信息。 Thanks! 谢谢!

I got it solved with the help of How to run a cron job inside a docker container? 我在如何在Docker容器中运行cron作业的帮助下解决了 however, I had to add the line: 但是,我必须添加以下行:

RUN crontab /etc/cron.d/crontab 运行crontab /etc/cron.d/crontab

which basically Loads the crontab data from the specified file. 它基本上从指定的文件加载crontab数据。 If i did not do it that way, the cron daemon never starts. 如果我没有那样做,那么cron守护程序将永远不会启动。

Hope this helps however, still not clear if this is the best way to do this. 希望这会有所帮助,但是仍然不清楚这是否是最好的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM