Docker & Cron - Include cron through docker-compose file?

I need to use cron for my Nextcloud setup, but I’m having trouble getting it right.

I’d like to not use the host’s crontab, but unfortunately it’s currently the only thing that works reliable. Other solutions like posted here don’t work:

nextcloud-cron | su: must be run from a terminal
nextcloud-cron | Sat Jan 26 11:46:05 UTC 2019 - Running cron finished

I’ve tried a different approach from another file I’ve found, but that too doesn’t work:

  cron:
    image: nextcloud:15-apache
    container_name: nextcloud-cron
    restart: always
    networks:
      - backend
    user: www-data
    depends_on:
      - postgres
    volumes:
      - nextcloud-data:/var/www/html
    entrypoint: |
      bash -c 'bash -s <<EOF
        trap "break;exit" SIGHUP SIGINT SIGTERM
        while [ ! -f /var/www/html/config/config.php ]; do
          sleep 1
        done
        while true; do
          echo "Running cron…"
          php -f /var/www/html/cron.php
          echo "Done."
          sleep 15m
        done
      EOF'

Resulting in:

nextcloud-cron | Running cron…

Which never finishes :frowning:

Any suggestion on how to fix it? Or alternative solutions? I’d really like to have a solution that I can implement through a docker-compose file.

Edit: I forgot, executing the cron.php from host works fine with the following line:
docker exec --user www-data nextcloud php cron.php

in the image (nc15:latest) is a file /etc/crontabs/www-data which contains
the line */15 * * * * php -f /var/www/html/cron.php
that should do the job.
did you check if that file is in your container?

Unfortunately the file isn’t there, even in a newly created container.

you may try to create one and see if cron is running in the container. i’m not if it is so.
normally i use the hosts cron with docker exec.

As mentioned above, even in a newly created container the file isn’t there.

Edit: Sorry, misunderstood. But cron doesn’t run in the container AFAIK.

Thanks, I’ll take a look at it.