Docker cron Jobs

Posted on Aug 31, 2024

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.

  1. Run crontab -e on the host system to edit the cron job.
  2. 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