Run crontab with docker image
Problem
You have put your application in docker image, and you have cron task to run.
Solution
Put your crontab script to the image too, and run both from docker-compose.
Say you have a crontab task like this:
10 * * * * python3 /app/del_tmp_file.pyPut those lines to a file like
doc/project.cronIn
Dockerfile:1
2COPY doc/project.cron /etc/cron.d/project.cron
RUN chmod 0644 /etc/cron.d/project.cron && crontab /etc/cron.d/project.cronThis will add your cron task to crontab
Now you already have put the crontab and application to your docker image. Edit docker-compose to start both:
1 | version: "3" |
The key is for run the crontab, make the entrypoint to be ["cron", "-f"].