Nextcloud install sometimes fails with "Failed to connect to the database" error

Some users report having issues with setting up nextcloud with the following error message:

Error while trying to create admin user: Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000] [2002] No such file or directory

I was not able to reproduce this on an Omnia with Turris OS 6.1.0.

cc @sborek