Obscure way to use unix socket for Redis
The parameter passing causes problems from the Docker container environment all the way to the phpredis->pconnect when using unix socket. The phpredis is kind of requiring the port setting to -1 if the host is actually a unix socket path starting with '/'. However in this image, the entrypoint.sh defaults REDIS_HOST_PORT to 6379, which would eventually passing into phpredis.
This would work though:
environment:
REDIS_HOST: /tmp/redis.sock
REDIS_HOST_PORT: -1
Good catch!
I didn't initially encounter this issue because I switched to UNIX socket use in my instances after they were already live. And when I did so I only modified config.php on the nc-app servers (where port 0 is specified). That is, I never added a REDIS_HOST to my Docker compose when I transitioned.
I encountered this problem though when I cleaned up my compose files.
The issue heres are two-fold:
-
If REDIS_HOST is specified in compose, than the config.php is always overridden with whatever is specified in it (via redis.config.php). And that'd be fine, but the way that redis.config.php currently does things, if a UNIX socket is specified than $CONFIG['redis']['port'] is simply left as null (which doesn't match the documented NC configuration parameters for sockets which specify a port 0): https://docs.nextcloud.com/server/25/admin_manual/configuration_server/caching_configuration.html#id2
-
phpredis's handling of socket connections and internal code for settling upon the default port was a little whacky. This was fixed in https://github.com/phpredis/phpredis/pull/2187 but that's not in any released version of phpredis including v5.3.7 (and that's what the NC docker image uses).
These two situations combined mean that REDIS_HOST_PORT is not an optional parameter for UNIX socket connections. And, worse, it's a non-sensical parameter because there is no proper port to specify for a UNIX socket connection.
Your workaround - specifying the optional REDIS_HOST_PORT fixes things (either 0 or -1 appear to function, but not specifying anything leaves things broken; and I suspect any value other than null would work since it'll ultimately be a noop for a UNIX socket connection).
Given that the documented NC configuration parameters say to specify port 0 in config.php for UNIX sockets (which works in a standard NC install, but not via the docker container - unless one explicitly sets REDIS_HOST_PORT in compose) I suggest a small change to redis.config.php to set the port to 0 if a UNIX socket is specified as the REDIS_HOST and no port is provided (and there generally won't be/shouldn't be).
This should allow all approaches to work when REDIS_HOST is a UNIX socket:
- no REDIS_HOST_PORT specified in Compose (currently documented behavior for NC Docker)
- a REDIS_HOST_PORT is specified (i.e. 0) (the only current way to gain a redis configuration equivalent to non-Docker NC)
- phpredis >5.3.7 is released (which seems to have better handling of default ports)
I have it working in my environment. I'll submit a PR.