Installation Error "SQLSTATE[HY000][2002] Connection Refused"

Fresh installation using docker for NextCloud and MariaDB running bare on debian 9, I encountered this issue, and am unsure how to proceed.

Steps taken:
database user can see the nextcloud database and has been granted all privs (and the database name is entered correctly into the web ui)
database user logs in via mysql without problem
database responds on port 3306 via web page test

through research i’ve seen others encounter a similar issue with using “localhost:3306” in place of “127.0.0.1:3306” or “system-ip:3306”, in my case I have tried all of these to no avail.

in a docker environment localhost/127.0.0.1 always refers to the container itself. and not to the host. each container has it’s own localhost/127.0.0.1. they have all there own ip address. docker inspect ... will show you. host-ip:3306 (system-ip?) only works if you expose the containers port the the world. (kind of port forewarding).

and in mysql there is a differnece between localhost and 127.0.0.1 as well. as far as i know localhost in this context means connect via unix socket.


https://hub.docker.com/_/nextcloud

did you try to use “Auto configuration via environment variables”? in your case MYSQL_HOST should be the name of the mariadb container.

I’m using docker-compose and for me autoconfiguration did not work. It always asks me for the data on the first setup screen.