docker icon indicating copy to clipboard operation
docker copied to clipboard

Doc/Sample improvement: cron via docker-compose needs Redis-environment as well

Open VolkerStolz opened this issue 3 months ago • 2 comments

This had me scratching my head a bit: I've set REDIS_HOST for the app:-target in the Apache docker-compose-file, and every five minutes (when cron comes around) I would get Redis server went away stains in the log.

It turns out that of course the solution is to pass the REDIS_{HOST, PORT} environment variables also to the cron:-target, e.g. in https://github.com/nextcloud/docker/blob/4cf9a20fdf5740e92e3b213a52d463c88449559a/.examples/docker-compose/with-nginx-proxy/postgres/apache/compose.yaml#L41.

I suggest to add the REDIS_*-variables to the cron:-section in the example template (possibly elsewhere?) to remind folks to do this.

[Or I misdiagnosed the issue, and I have some other problem – I had assumed the whole time that the cron-container would just trigger tasks in the running instance, but apparently that wasn't the case.]

VolkerStolz avatar Sep 09 '25 07:09 VolkerStolz

The cron container picks up config/config.php from the main container since /var/www/html is shared between them.

Typically that will already contain you entire config, since the full config is merged and written there at installation time by Nextcloud itself.

I guess there could be some edge cases where the environment variable is the only place the redis config would be, such as if added after install time and a config written hasn't yet had a reason to happen. Can you share a bit more context about your deployment situation?

joshtrichards avatar Sep 11 '25 18:09 joshtrichards

Thanks for making me look into this with fresh eyes – of course you're right. I didn't notice that I had made TWO changes in my fix in the docker-compose file: the first one were the REDIS_*-variables, but the second one was mounting the unix-socket into the cron-container as well. This last step is the culprit, since indeed config.php is already populated, but then for the cron-container points to the missing socket. Kind of obvious in hindsight, but complicated by the fact that in the log you have to infer that the error messages is actually coming from a task in a different container.

I'm half-willing to chalk this up as a layer-8 problem, but given the time I spent looking into this, I hope it might save someone else an hour or two if there'd be a comment in the right place that if you use a unix-socket (for either Redis or even the db!), then of course you need to mount the socket in cron as well.

VolkerStolz avatar Sep 11 '25 21:09 VolkerStolz