So okay, this looks good and also match with the docs but this one here isn’t answered anywhere: Where can i set up the crontab itself? So you command is calling cron.php every 5 minutes and cron.php is doing his thing. Lets say i want to sync my files now every 5 minutes, before i added this in my crontab -e “sudo docker exec --user www-data nextcloud_app php occ files:scan --all” Where do i add know this “php occ files:scan --all” command after your command?
Sorry to revive this old topic but I think I need to make a few things clear to anyone in the future.
There is a lot of… I’m not sure what to call it… confusion I guess, around this. I’ll attempt to clear things up for future people.
The docs say to create a cron job. Great how?
Well there are basically two branches of Nextcloud users. The kind that have it running on bare metal or the ones running Nextcloud in Docker.
If you are running it bare metal create a cron job however you typically do that.
sudo crontab -e
or sudo crontab -u web-data -e
The documentation I believe was written for people using Nextcloud on bare metal.
The solution if you are using Docker has basically two options:
-
Create a cron job in the host system that calls a process in the docker container
a)sudo crontab -e
this will edit your cron jobs on the host and add,
b)*/5 * * * * docker exec -u www-data *conatiner_name* php /var/www/html/cron.php
this will execute the docker command every 5 minutes. Container_name is the name of the container. -
Create a cron docker container inside of your nextcloud container as an example here is the snippet of my Compose file:
cron:
image: nextcloud
container_name: nextcloud-cron
restart: always
volumes:
- ${PATH_TO_DATA}/nextcloud/html:/var/www/html
environment:
- POSTGRES_HOST=postgresdb
- POSTGRES_DB=${POSTGRES_DB}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- REDIS_HOST=redis
entrypoint: /cron.sh
depends_on:
- postgresdb
- redisdsadf
NOTE: This cron service is using Volume Sharing. It’s using the same volume as my nextcloud service inside my compose file. In order for this cron service to work properly it has to have exactly the same environment and configuration as the nextcloud service.
So those are the two options if you are using docker. Now from what I’ve seen / read what is happening is people are forgetting to match the same environment and then the cron job does not work.
Then they resort to option 1.
Note that option 2 is what they use at Docker Official Image
I’m using option 2.
Now to answer parents question. For anyone in the future as I’m sure it’s solved for him.
What you can do is what @R0Wi suggested using my example:
cron:
image: nextcloud
container_name: nextcloud-cron
restart: always
volumes:
- ${PATH_TO_DATA}/nextcloud/html:/var/www/html
- ${PATH_TO_DATA}/nextcloud/mycronfile:/var/spool/cron/crontabs/www-data
environment:
- POSTGRES_HOST=postgresdb
- POSTGRES_DB=${POSTGRES_DB}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- REDIS_HOST=redis
entrypoint: /cron.sh
depends_on:
- postgresdb
- redis
You can then put whatever information in mycronfile such as:
*/5 * * * * php -f /var/www/html/cron.php
0 0 * * 0 php -f /var/www/html/occ fulltextsearch:index
See his post here
I hope that will clear some things up for people. Bottom line the cron container needs to have the exact same access / information as the nextcloud container and you should be golden.
For references see:
- Clarification Regarding Cron Jobs & Setup/Config
- Nextcloud Docker Container - best way to run cron job
- Docker setup & cron
I’m sure I read more at some point. If I made any mistakes feel free to correct me.