The easiest Way to set up Cron for the Nextcloud Docker Image

For Nextcloud to work properly and fast it has to do some tasks regularly. Don't ask me what it has to do, but I'm pretty sure it's not a good idea to not do it.

This post will show you how to tell your Nextcloud docker container to run the required tasks at the recommended intervals.

1. Tell Nextcloud to use Cron

For that log in to your Nextcloud as a user with admin privileges. Then click on your profile picture in the top right -> Settings -> Basic Settings


Sidenote:

On the top of the page you can see when the last time was when the background jobs (i.e. the tasks we are taking about) ran. If it's always less than 5 Minutes and the dot is always green, you don't actually have to change anything and can stop right here.


and set it to cron.

2. Find the name of your Nextcloud container

For this you just have to run

docker ps

and have a look at the last column. The name of my container is nextcloud_app_1. This means that I can trigger the backgroud jobs using

docker exec -u www-data nextcloud_add_1 php cron.php

on the host machine. Now we just need to tell the computer to run that every five minutes.

3. Setup a Cron Job

Execute

crontab -e

and choose a text editor if you get asked. Now add

*/5 * * * * docker exec -u www-data nextcloud_app_1 php cron.php

to the bottom of the file, but don't forget to edit the name of the container if yours is different from mine. Also make sure that the file ends with an empty line.

Now Nextcloud's background jobs are running every five minutes.