Cron job not running using official docker apache example

Support intro

Sorry to hear you’re facing problems. :slightly_frowning_face:

The community help forum (help.nextcloud.com) is for home and non-enterprise users. Support is provided by other community members on a best effort / “as available” basis. All of those responding are volunteering their time to help you.

If you’re using Nextcloud in a business/critical setting, paid and SLA-based support services can be accessed via portal.nextcloud.com where Nextcloud engineers can help ensure your business keeps running smoothly.

Getting help

In order to help you as efficiently (and quickly!) as possible, please fill in as much of the below requested information as you can.

Before clicking submit: Please check if your query is already addressed via the following resources:

(Utilizing these existing resources is typically faster. It also helps reduce the load on our generous volunteers while elevating the signal to noise ratio of the forums otherwise arising from the same queries being posted repeatedly).

Some or all of the below information will be requested if it isn’t supplied; for fastest response please provide as much as you can. :heart:

The Basics

  • Nextcloud Server version (e.g., 29.x.x):
    • 30.0.5.1
  • Operating system and version (e.g., Ubuntu 24.04):
    • Docker image (apache) on Debian 12
  • Web server and version (e.g, Apache 2.4.25):
    • 2.4.62
  • PHP version (e.g, 8.3):
    • 8.2.27
  • Installation method (e.g. AlO, NCP, Bare Metal/Archive, etc.)
    • Custom 30.0.4 docker image using official cron example for apache base
  • Are you using CloudfIare, mod_security, or similar? (Yes / No)
    • no

Summary of the issue you are facing:

Cannot get the official cron example (apache docker image) running in my nextcloud instance.

Steps to replicate it (hint: details matter!):

  1. Create a fresh docker image “nextcloud:test” using the official examples
  2. Used the following docker-compose.yml. I wasn’t quite sure if the cron jobs were sought under root or www-data, so I put both.
services:
  app:
    image: nextcloud:test
    restart: unless-stopped
    ports:
      - 8089:80
    volumes:
      # Set timezone same as host
      - /etc/localtime:/etc/localtime:ro
      - ./www_html:/var/www/html
      - ./crontab:/var/spool/cron/crontabs/www-data
      - ./crontab.root:/var/spool/cron/crontabs/root

  1. The two crontab files “crontab” and “crontab.root” contain
* * * * * date >> /tmp/cron.txt
* * * * * echo "I am root" >> /tmp/cron.txt

Log entries

Nextcloud

Please provide the log entries from your Nextcloud log that are generated during the time of problem (via the Copy raw option from Administration settings->Logging screen or from your nextcloud.log located in your data directory). Feel free to use a pastebin/gist service if necessary.

The container logs show "crond: crond (busybox 1.35.0) started, log level 8.

Initializing nextcloud 30.0.5.1 ...
New nextcloud instance
Next step: Access your instance to finish the web-based installation!
Hint: You can specify NEXTCLOUD_ADMIN_USER and NEXTCLOUD_ADMIN_PASSWORD and the database variables _prior to first launch_ to fully automate initial installation.
Initializing finished
=> Searching for scripts (*.sh) to run, located in the folder: /docker-entrypoint-hooks.d/before-starting
2025-01-30 10:55:07,063 CRIT Supervisor is running as root.  Privileges were not dropped because no user is specified in the config file.  If you intend to run as root, you can set user=root in the config file to avoid this message.
crond: crond (busybox 1.35.0) started, log level 8
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.20.0.2. Set the 'ServerName' directive globally to suppress this message
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.20.0.2. Set the 'ServerName' directive globally to suppress this message
[Thu Jan 30 10:55:08.249311 2025] [mpm_prefork:notice] [pid 129:tid 129] AH00163: Apache/2.4.62 (Debian) PHP/8.2.27 configured -- resuming normal operations
[Thu Jan 30 10:55:08.249850 2025] [core:notice] [pid 129:tid 129] AH00094: Command line: 'apache2 -D FOREGROUND'

When I exec into container and list /tmp I do not see what is expected from the cron jobs that were configured - cron.txt with either the ‘date’ or the text “I am root” written into it. There is no cron.txt present under /tmp no matter how long I wait.

$ docker exec -it test-app-1 bash

root@7a11f36a5527:/var/www/html# date
Thu Jan 30 11:01:38 PST 2025

root@7a11f36a5527:/var/www/html# ls -al /tmp
total 8
drwxrwxrwt 1 root root 4096 Jan 30 10:55 .
drwxr-xr-x 1 root root 4096 Jan 30 10:54 ..

root@7a11f36a5527:/var/www/html# date
Thu Jan 30 11:12:21 PST 2025

root@7a11f36a5527:/var/www/html# ls -al /tmp
total 8
drwxrwxrwt 1 root root 4096 Jan 30 10:55 .
drwxr-xr-x 1 root root 4096 Jan 30 10:54 ..

The process list shows that supervisord and busybox crond are running

root@aab600037ee6:/var/www/html# ps -ef
UID          PID    PPID  C STIME TTY          TIME CMD
root           1       0  1 11:08 ?        00:00:00 /usr/bin/python3 /usr/bin/supervisord -c /supervisord.conf
root          47       1  0 11:08 ?        00:00:00 apache2 -DFOREGROUND
root          48       1  0 11:08 ?        00:00:00 busybox crond -f -L /dev/stdout
www-data      59      47  0 11:08 ?        00:00:00 apache2 -DFOREGROUND
www-data      60      47  0 11:08 ?        00:00:00 apache2 -DFOREGROUND
www-data      61      47  0 11:08 ?        00:00:00 apache2 -DFOREGROUND
www-data      62      47  0 11:08 ?        00:00:00 apache2 -DFOREGROUND
www-data      63      47  0 11:08 ?        00:00:00 apache2 -DFOREGROUND
root          64       0  2 11:08 pts/0    00:00:00 bash
root          70      64  0 11:08 pts/0    00:00:00 ps -ef

I have seen in other posts recommending setting up cron in the host environment. That’ll be my last resort but I would like to keep all of this self-contained in the NC deployment so I can easily move it to another system as needed. It’s a small personal instance so it’s fine that my deployment is running more than a single service.

Can someone help point me in the right direction? Where can I look to troubleshoot why the simple cron jobs aren’t firing? Again, I wasn’t sure if the cronjob was expected under root or www-data (the latter I think) but provided but to cover all bases.

Appreciate the help!

I haven’t personally tested the supervisor method in a while, but the one that I typically suggest is the other one, which doesn’t require any image building/customization and is still fully self-contained in your Compose file - example:

Are you trying to run other custom cron jobs other than Nextcloud’s cron.php?

P.S. If you overwrite /var/spool/cron/crontabs/www-data in the container you’re effectively deleting the existing entry that is shipped in the image.