Cron don't work

Good day. Please tell me what am I doing wrong and why the cron is not running?

ubuntu 22 04


version: "2.1"

    image: nextcloud
    container_name: nextcloud
       - PUID=1000
       - PGID=1000
      - TZ=Europe/Netherlands
      # - REDIS_HOST=redis-nextcloud
      - ./nextcloud/apps:/var/www/html/apps
      - ./nextcloud/custom_apps:/var/www/html/custom_apps
      - ./nextcloud/config:/var/www/html/config
      - ./nextcloud/data:/var/www/html/data
      - ./nextcloud.ini:/usr/local/etc/php/conf.d/nextcloud.ini
      - 13370:80
    restart: unless-stopped
      - postgres-nextcloud
      # - redis-nextcloud

    image: postgres
    container_name: postgres-nextcloud
    restart: unless-stopped
      - POSTGRES_DB=nextcloud
      - POSTGRES_USER=nextcloud
      - ./DB:/var/lib/postgresql/data

cron entry: */5 * * * * sudo /usr/bin/docker exec -u www-data nextcloud php -f /var/www/html/cron.php

(I tried other modifications that I could find on the Internet, the result is the same everywhere, it does not work)

I’ll also immediately add a second question that may arise.
There are two containers running on the machine with nextcloud. How can I add its execution to the second connector? Do not really understand. New to these things… :see_no_evil:

Your cron entry is wrong. First try on the command line if it works, then put it in cron.
I never used sudo in cron commands, but depending on your configuration that might not work. If you need root rights, then put it in the root crontab.
Your command executes it in container “nextcloud”. If you have a second container, it will have a different name which you should use.

See also: Nextcloud Docker Container - best way to run cron job - #4 by sanctimon

docker exec -it CONTAINERNAME crontab -e -u www-data should open your crontab, then put there */5 * * * * php -f /var/www/html/cron.php
Or do it like here: Docker setup & cron - #7 by lazmol

1 Like

make sure the location of cron.php is /var/www/html or /var/www/html/apps.
add user www-data to docker group.
modify your cron entry to:
*/5 * * * * docker exec -u www-data [your-nextcloud-container] php [your-cron.php-location]

I did these and it worked :slightly_smiling_face:

add to your nextcloud section of compose-file:
- postgres-nextcloud
- redis-nextcloud (if you use redis)”

I suggest using Redis server for Nextcloud Transactional File Locking mechanism and memory caching according to and .html
So there will be 3 containers at once created with your compose-file, nextcloud, postgres-nextcloud and redis-nextcloud.

I tried running this command directly in manual mode. And everything is fine (a green check mark appears on the nextcloud website)

But if I enter the command into cron, it stops executing.
I don’t understand why.

I also added the user to the group. But the result is similar to what I wrote above.

did you crate cron job for root or www-data user?