Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (29.3k points)

I tried to run a cron job inside a Docker container

but nothing works for me

my container have only cron.daily and cron.weekly file

crontab,cron.d,cron.hourly ... are absent in my container

crontab -e also not working

my container runs with /bin/bash

1 Answer

0 votes
by (50.2k points)

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 * * * * / >> /var/log/script.log


# start cron

/usr/sbin/crond -f -l 8


# code goes here.

echo "This is a script, run by cron!"


FROM alpine:3.3

ADD crontab.txt /crontab.txt



RUN chmod 755 / /

RUN /usr/bin/crontab /crontab.txt

CMD ["/"]

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.

Browse Categories