16

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!

the_ccalderon
  • 2,006
  • 2
  • 13
  • 24
  • 1
    Have a look at this: https://stackoverflow.com/questions/37458287/how-to-run-a-cron-job-inside-a-docker-container It also starts a cron job inside a container. – Saqib Ahmed Apr 24 '18 at 06:45

1 Answers1

9

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.

the_ccalderon
  • 2,006
  • 2
  • 13
  • 24
  • 10
    Please take into consideration invoking cron outside container (like in k8s) when scaling application. Cron jobs might overlap when containers are scaled. – Athlan Aug 24 '19 at 17:37