Run cron inside a docker container manually

Table of Content

On production we have two separate services for web and cron but for some testing it was needed to run a command inside a docker container manually.
All tutorials I found explaining how to prepare a docker image with cron inside but it’s not what I needed.

The solution is pretty simple. Run the cron deamon itself in a background mode:

cron -f -l 2

Login into your docker container and add a command to the crontab schedule file:

vi /etc/crontab
...
* * * * * touch /tmp/testing.txt

That’s it. Cron is working, you can any command you need.

Leave a Reply

Your email address will not be published. Required fields are marked *