Docker: SQLSTATE[HY000] [2002] Connection refused

Created on 2 Apr 2019  路  4Comments  路  Source: nextcloud/docker

Hi

After one week of google and trying I ended up here asking the nextcloud community.

My Setup:

  • Ubuntu 18.04 VPS
  • Plesk with Docker

I installed nextcloud docker container by plesk. When I go to the nextcloud web installer I have to type in mysql database, ip, user, password etc.

After that I get always the same error:

"Error while trying to create admin user: Failed to connect to the database: An exception occured in driver: SQLSTATE[HY000] [2002] Connection refused"

I tried as host database IP: localhost:3306 and 127.0.0.1:3306

Maybe the nextcloud docker container have no acces to the plesk mysql DB, so I decided to install mariadb in a docker composer and added the mariadb to plesk.

I tried as host database IP: localhost:3307 and 127.0.0.1:3307
-> Same error as above

I'm not native english so sorry for wired english writing.

Hope someone mind to help me
Pascito

Most helpful comment

In docker, the database host is not localhost but the container name of the database service. If your database container is named nextcloud_db, then your hostname should be nextcloud_db and not localhost

All 4 comments

In docker, the database host is not localhost but the container name of the database service. If your database container is named nextcloud_db, then your hostname should be nextcloud_db and not localhost

stumbled upon the same problem. maybe this should go in the README?

This is a duplicate of #540.

After a lot of reading I've solved the same problem on my machine. Simply speaking, I use the VM's ip address instead of 127.0.0.1 or localhost, eg. 192.168.4.213:3307.

Just for reference, here is the description of my setup:
I install PVE into an old laptop. There are two VMs running on PVE (1. LEDE router; 2. OMV Nas). and I install the mariadb and nextcloud on OMV by docker.
Router IP: 192.168.4.1
OMV IP: 192.168.4.213
mariaDB port: 3307

Here is what I thought. So basically speaking, there shouldn't be any problem of running the nextcloud or mariadb installed by docker. On my experience, the problems usually are about grant the proper permission of the folders and set the right connection between different containers.

And I don't know if I express myself clearly, because this whole computer science thing is just a hobby, what I study has nothing to do with it. So I don't think I am using or describing all these terms precisely.

At last, I do wonder why this happened? Because I didn't encounter with such problem when I set the nextcloud on my old router before.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pierreozoux picture pierreozoux  路  3Comments

k1ngf15h3r picture k1ngf15h3r  路  3Comments

nthack picture nthack  路  3Comments

alexbarnhill picture alexbarnhill  路  3Comments

pr4xx picture pr4xx  路  4Comments