There are 3 ways.
Way 1 - Write an entrypoint script.
- invoke cron.
- Command to run your scripts.
Pros:
- Crons goes together with your docker image = Less headache,
Cons:
- Not inline with Docker concept of "one duty per one docker instance".
Way 2 - Run cron as part of the host
Cron job will be a docker run command.
Pros:
- Goes inline with Docker concept of "one duty per one docker instance".
Cons:
- Take care of setting up docker command on host.
Way 3 - Use schedule jobs (in Kubernetes)
Pros
- Goes inline with docker concepts
- Kubernetes script takes care in all your deployments.
I am now following Way 2 - because, I want to align with Docker concepts.
Also, since I am planning to move to Kubernetes (or Docker Swarm), this strategy will help me in migration.
I am not using Kubernetes in production, because of company deadlines and the learning curve there.
Ideally, I feel that schedule jobs should be used to solve Crons.
In Schedule jobs, a docker instance is created for the job and removed once the task is done.