Docker cron Jobs
Setting up cron jobs to run inside docker containers
I was having issues with cron jobs not running when I wanted them to in my Nextcloud container. Instead of trying to edit cron jobs in the container, I decided the easier way was to run the cron jobs on the host machine and use the docker exec command. Here’s how to do it.
- Run crontab -e on the host system to edit the cron job.
- Add in the cron job. In this example, I’m running a cron job to kick off the php /var/www/html/cron.php file every 8 minutes.
crontab -e
*/8 * * * * docker exec -u www-data shannon_app_1 php /var/www/html/cron.php