I would like to give an example of how I created a cron job so that you can implement your own. To run cron container first create the following files:-
See the following what should be in the files as mentioned above.
*/30 * * * * /script.sh >> /var/log/script.log
# start cron
/usr/sbin/crond -f -l 8
# code goes here.
echo "This is a script, run by cron!"
ADD crontab.txt /crontab.txt
ADD script.sh /script.sh
COPY entry.sh /entry.sh
RUN chmod 755 /script.sh /entry.sh
RUN /usr/bin/crontab /crontab.txt
Then, build the docker file using the following commands
Sudo docker build <dockerfile-name> .
Sudo docker run -d <dockerfile-name>
Thus, we can build a cron job inside a Docker container. So now you can easily implement by following through this.
If you are searching for more information on Docker then you can join Docker Training by Intellipaat.