Search code examples
dockercrondocker-composedocker-swarm

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. I already "dockerized" the node js backend but now I'm trying to do the same with the Perl Workers.

Already dockerized the Perl application itself however, as the "jobs" from the queue are consumed based on a crontab (i.e every 2 mins) my question would be:

What's the best way to accomplish this when having a stack built from a docker-compose file?

Let me know if I should provide more details. Thanks!


Solution

  • I got it solved with the help of How to run a cron job inside a docker container? however, I had to add the line:

    RUN crontab /etc/cron.d/crontab

    which basically Loads the crontab data from the specified file. If i did not do it that way, the cron daemon never starts.

    Hope this helps however, still not clear if this is the best way to do this.