I'm using a docker-compose. I have a web and a worker service.
version: '3'
services:
web:
build: .
environment:
- "*"
links:
- redis
- memcached
ports:
- "80:8001"
- "443:8001"
worker:
build: .
command: ["/bin/bash", "/home/django/start_celery.sh"]
environment:
- "*"
links:
- redis
- memcached
memcached:
image: memcached
ports:
- "11211:11211"
redis:
image: redis
ports:
- "6379:6379"
I need to run crons (scheduled tasks) on worker service.
And I dont want to hardcode the crontab in Dockerfile as I'm using same dockerfile for both the services.
So what is the best approach for this?
You can try the following Opensource tool for scheduling crons in the docker-compose.
https://github.com/mcuadros/ofelia
eg:
[job-service-run "service-executed-on-new-container"]
schedule = 0,20,40 * * * *
image = ubuntu
network = swarm_network
command = touch /tmp/example
In case you are planning to utilize the image in any of the cloud platforms.
For Eg.
AWS: You can also have a look at ECS scheduler
https://docs.aws.amazon.com/AmazonECS/latest/developerguide/scheduled_tasks.html
GCP: Kubernetes Engine CronScheduler
https://cloud.google.com/kubernetes-engine/docs/how-to/cronjobs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With