Nextcloud Docker setup - Help needed with cron

Hello,

I am new to nextcloud and I have been setting up the official nextcloud container in docker with an external MariaDB running in a different container, as well as REDIS and a second nextcloud container for CRON like I have seen in many examples. Everything is running fine including corn (according to my admin dashboard in Nextcloud)

There is however one thing I do not fully understand, where and how do I add cron jobs in this configuration?

I need to add some cron jobs for example for the previewgenerator app I would need to add a cron job that runs regularly and updates previews but am at a loss on how to do it in this configuration.

My initial thought was that I would get into the console of the nextcloud-cron container and set it up there by running something lik sudo crontab -u www-data -e but that doesn’t work. I am already root in the container and it doesn’t recognize the crontab command. There are folders for /etc/cron.d and /etc/cron.daily.

So how would add occ preview:pre-generate to a cronjob that runs at least ever 24hours or so?

Please see my docker compose file:

---
services:
  nextcloud:
    image: nextcloud
    container_name: nextcloud
    restart: unless-stopped
    network_mode: nextcloud-net
    ports:
      - 80:80
    external_links:
      - mariadb:mariadb
    volumes:
      - ~/Users/docker/nextcloud/nextcloud:/var/www/html
      - ~/Users/docker/nextcloud/config:/var/www/html/config
      - /Volumes/Files/nextcloud:/var/www/html/data
    environment:
      - TZ=America/New_York
      - MYSQL_DATABASE
      - MYSQL_USER
      - MYSQL_PASSWORD
      - MYSQL_HOST
      - REDIS_HOST
      - REDIS_HOST_PORT
      - REDIS_HOST_PASSWORD
      - NEXTCLOUD_ADMIN_USER
      - NEXTCLOUD_ADMIN_PASSWORD
      - NEXTCLOUD_TRUSTED_DOMAINS
      - PHP_MEMORY_LIMIT
      - PHP_UPLOAD_LIMIT
      - APACHE_BODY_LIMIT
    depends_on:
      - nextcloud-redis

  cron:
    image: nextcloud
    container_name: nextcloud-cron
    volumes:
      - ~/Users/docker/nextcloud/nextcloud:/var/www/html
      - ~/Users/docker/nextcloud/config:/var/www/html/config
      - /Volumes/Files/nextcloud:/var/www/html/data
    entrypoint: /cron.sh
    restart: unless-stopped
    network_mode: nextcloud-net
  
  nextcloud-redis:
   image: redis:alpine
   container_name: nextcloud-redis
   hostname: nextcloud-redis
   volumes:
      - ~/Users/docker/redis:/data
   ports:
      - 6379:6379
   restart: unless-stopped
   command: redis-server --requirepass "REDIS-Password"
   network_mode: nextcloud-net

Let me know if you need anything other info in order to help!

Thank you so much!

this are not “cron” jobs in terms of admin doing some task it’s more “internal” stuff - installed apps could register jobs which will run automatically (background jobs)… and there is usually no need to do something manual - AFAIK preview generator scans the system on it’s own doesn’t need additional cron jobs. I you need to run some admin task you can use your OS scheduler/cron jobs to start you admin tasks.

https://docs.nextcloud.com/server/latest/developer_manual/basics/backgroundjobs.html

Ok, that does make sense but then I have to ask what is the nextcloud-cron container for?

As for preview generator:

Is that the case though?

This says to create a cron job:

https://github.com/nextcloud/previewgenerator#how-to-use-the-app

After reading it again says system cronjob, since I run it in portainer on a server what would that mean?

I thought that’s what the cron container is for but guess I am wrong.

Sorry but I am getting pretty confused at the moment.

to run background jobs.

you must create another container running cron.

So another one besides the nextcloud-cron container I already have?
Sorry but really having trouble wrapping my head around this one.
I thought that is exactly the one and that it is there where I would add cron jobs if I had to add any manually.

use your OS scheduler to run your custom jobs. Cron container is for NC internal jobs.

Docker .examples
docker-compose-setup-with-notify-push-2024

Ok, that makes sense then. Thank you!