John2
March 13, 2023, 4:51pm
1
Nextcloud Docker Container - best way to run cron job
I have been doing some test setups of running NextCloud in a docker container. One thing I am still a little confused on and would like to hear your thoughts about, is running the cron process. I am a little surprised that it is not the default, but I found two methods of running the cron job in a container.
The first is from Docker Hub NextCloud examples (https://github.com/nextcloud/docker/tree/master/.examples ). It “uses supervisor to run the cron job inside the container (so no extra container is needed). This image runs supervisord to start nextcloud and cron as two seperate processes inside the container.” This requires a custom image build (https://github.com/nextcloud/docker/blob/master/.examples/dockerfiles/cron/apache/Dockerfile ). Other than that it is not complicated.
The second I found is also from the examples
(https://github.com/nextcloud/docker/tree/master/.examples/docker-compose/with-nginx-proxy/mariadb/apache ). It is not explained well, but I believe they are just running a second NextCloud container to run the cron job. I am guessing this works because both containers use the same database and document store? Not sure about that.
My questions are:
What is the best way to run the cron job? (in regards to efficiency, ease of backups and restores, etc)
Is one an older way and the examples have just not been updated yet?
Thanks for your thoughts on this.
wwe
March 13, 2023, 9:12pm
2
hello @John2 welcome back in the forum
Please use the search - lot of issues have been discussed already like
Hello
I’m running my nextclud instance via docker (compose file adopted from here ). There is already a container running /cron.sh, which starts a busybox with cron, which starts cron.php every 5 minutes.
Now my question is: how to do i add additional tasks? (i.e. ./occ fulltextsearch:index)
I do not want to rebuild the nextcloud image just for adding a cron task. And i do not want to use the host for managing tasks in the container (host systemd oder host cron)
any way to manage this?
Greet…
Hi guys,
Host: proxmox
VM: Ubuntu server 18.04.5 LTS.
Nextcloud: 20.0.4
Everything updated
I run Nginx Proxy Manager as my reverse proxy also in a separate container.
I installed Nextcloud via the docker-compose example but I customized it of course… insecure/mariadb-cron-redis/apache/docker-compose.yml
My docker-compose file:
version: '3'
services:
db:
image: mariadb
command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
restart: always
volumes:
- .…
there are multiple ways to run cron with docker. I think most common way is to setup another separate “cron” container using same image volume mounts, config and env variables as “app” with different entrypoint :
dev-nextcloud-cron:
image: nextcloud:${NEXTCLOUD_VERSION}
container_name: dev-nextcloud-cron
restart: unless-stopped
env_file:
- ./nextcloud.env
- ./db.env
volumes:
- ./app:/var/www/html
- ./files:/var/www/html/data
- ./config:/var/www/html/config
entrypoint: /cron.sh
depends_on:
- dev-nextcloud-app
WebCF
April 17, 2023, 6:52am
3
I personally use:
docker exec -u www-data *containername* php /var/www/html/cron.php
which runs via system cron
4 Likes
I found this advice to be the most helpful of them all, as anything else means meddling with dockerfiles and the like.
What is perhaps not mentioned very clearly is that this command needs to be added to the crontab of root on the host system .
sudo crontab -e
Add this line to your file:
*/5 * * * * docker exec -u www-data nextcloud php /var/www/html/cron.php
Close and save.
8 Likes
I use this now
cron:
image: nextcloud
container_name: nextcloud-cron
restart: unless-stopped
depends_on:
- app
# env_file:
# - ./nextcloud.env
# - ./db.env
volumes:
- type: volume
source: nextcloud_app.persistent
target: /var/www/html
read_only: false
- type: volume
source: nextcloud_data.persistent
target: /var/www/html/data
read_only: false
entrypoint: /cron.sh
(Had to comment out the .env files, since I don’t have them). It starts fine, the logs of nextcloud-cron says:
nextcloud-cron
crond: crond (busybox 1.35.0) started, log level 0
crond: user:www-data entry:(null)
100001000010000100001000010000100001000010000100001000010000
111111111111111111111111
11111111111111111111111111111111
111111111111
1111111
crond: crond (busybox 1.35.0) started, log level 0
crond: user:www-data entry:(null)
100001000010000100001000010000100001000010000100001000010000
111111111111111111111111
11111111111111111111111111111111
111111111111
1111111
crond: user:www-data entry:(null)
100001000010000100001000010000100001000010000100001000010000
111111111111111111111111
11111111111111111111111111111111
111111111111
1111111
crond: wakeup dt=18
crond: file www-data:
crond: line php -f /var/www/html/cron.php
crond: wakeup dt=60
crond: file www-data:
crond: line php -f /var/www/html/cron.php
crond: wakeup dt=60
crond: file www-data:
crond: line php -f /var/www/html/cron.php
crond: wakeup dt=60
crond: file www-data:
crond: line php -f /var/www/html/cron.php
crond: job: 0 php -f /var/www/html/cron.php
crond: child running /bin/bash
crond: USER www-data pid 13 cmd php -f /var/www/html/cron.php
crond: wakeup dt=10
crond: crond (busybox 1.35.0) started, log level 0
crond: user:www-data entry:(null)
100001000010000100001000010000100001000010000100001000010000
111111111111111111111111
11111111111111111111111111111111
111111111111
1111111
crond: user:www-data entry:(null)
100001000010000100001000010000100001000010000100001000010000
111111111111111111111111
11111111111111111111111111111111
111111111111
1111111
crond: wakeup dt=50
crond: file www-data:
crond: line php -f /var/www/html/cron.php
crond: wakeup dt=60
crond: file www-data:
crond: line php -f /var/www/html/cron.php
crond: wakeup dt=60
crond: file www-data:
crond: line php -f /var/www/html/cron.php
crond: wakeup dt=60
crond: file www-data:
crond: line php -f /var/www/html/cron.php
crond: job: 0 php -f /var/www/html/cron.php
crond: child running /bin/bash
crond: USER www-data pid 12 cmd php -f /var/www/html/cron.php
crond: wakeup dt=10
crond: wakeup dt=10
crond: wakeup dt=10
crond: wakeup dt=10
crond: wakeup dt=10
crond: wakeup dt=10
crond: file www-data:
crond: line php -f /var/www/html/cron.php
crond: wakeup dt=10
crond: wakeup dt=10
crond: wakeup dt=10
crond: wakeup dt=10
crond: wakeup dt=10
crond: wakeup dt=10
crond: file www-data:
crond: line php -f /var/www/html/cron.php
crond: wakeup dt=10
crond: wakeup dt=10
crond: wakeup dt=10
crond: wakeup dt=10
crond: wakeup dt=10
crond: wakeup dt=10
crond: file www-data:
crond: line php -f /var/www/html/cron.php
crond: wakeup dt=10
crond: wakeup dt=10
crond: wakeup dt=10
crond: wakeup dt=10
crond: wakeup dt=10
crond: wakeup dt=10
crond: file www-data:
crond: line php -f /var/www/html/cron.php
crond: wakeup dt=10
crond: wakeup dt=10
crond: wakeup dt=10
crond: wakeup dt=10
crond: wakeup dt=10
crond: wakeup dt=10
crond: file www-data:
crond: line php -f /var/www/html/cron.php
crond: job: 12 php -f /var/www/html/cron.php
crond: user www-data: process already running: php -f /var/www/html/cron.php
crond: wakeup dt=10
crond: wakeup dt=10
crond: wakeup dt=10
crond: wakeup dt=10
crond: wakeup dt=10
crond: crond (busybox 1.35.0) started, log level 0
crond: user:www-data entry:(null)
100001000010000100001000010000100001000010000100001000010000
111111111111111111111111
11111111111111111111111111111111
111111111111
1111111
crond: user:www-data entry:(null)
100001000010000100001000010000100001000010000100001000010000
111111111111111111111111
11111111111111111111111111111111
111111111111
1111111
crond: wakeup dt=4
crond: file www-data:
crond: line php -f /var/www/html/cron.php
But when checking the issues as admin on the nextcloud instance it says there’s an error with cron and it hasn’t been run for many days. I have selected cron as the service to run background jobs with. How can I trouble shoot?
Sanctimon’s post is the way if you have the capability to access host cron. only different thing that i do is i have the cron line execute a shell script which basically just has the same line listed in the post
wwe
September 1, 2023, 7:26pm
7
there is a reason for .env files. speaking in simple words cron it another instance of Nextcloud application running specific tasks - for this reason it must have access to config and database - provide same config as you do for application container itself.