Ben Browning
Ben Browning

Reputation: 25

What are the trade-offs between running cron within a Docker container vs. running a Docker container from the host machine's cron?

I have a batch job in a Docker container that I want to run every day at 8:30am. What should I consider when deciding to either:

  1. Run the container from the host machine's crontab.
  2. Leave the container running, and set up cron within the container to handle the scheduling.

Thanks!

Upvotes: 0

Views: 665

Answers (1)

logix
logix

Reputation: 642

Advantages of 1:

  • Cron usually always starts on boot so you don't have to worry about starting your container when the host restarts
  • Logging occurs on your host
  • Easier to manage cron jobs because they're in one place

Disadvantages:

  • Have to maintain versioning of the crontab and scripts

Advantages of 2:

  • Self-contained
  • Reproducible containers with versionable Dockerfiles

Disadvantages:

  • Have to start the container on boot and make sure it stays running
  • Each container has it's own logs, so if you use a central logging server this makes it complicated
  • The container needs to be rebuilt on any changes to the cron job.

Upvotes: 1

Related Questions