requarks / wiki

Wiki.js | A modern and powerful wiki app built on Node.js
https://js.wiki
GNU Affero General Public License v3.0
24.64k stars 2.73k forks source link

DB access denied, is docker ignoring `DB_HOST`? #1945

Closed derek-shnosh closed 4 years ago

derek-shnosh commented 4 years ago

Question Running Ubuntu server, I have a MySQL database created and am using this command to start via docker: docker run -d --name wiki --restart unless-stopped -p 8081:3000 -e "DB_TYPE=mysql" -e "DB_HOST=10.19.128.210" -e "DB_PORT=3306" -e "DB_NAME=wikijs" -e "DB_USER=wikijs" -e "DB_PASS=omitted" requarks/wiki:2

Running sudo docker logs wiki shows the following error: error: Database Connection Error: ER_ACCESS_DENIED_ERROR undefined:undefined

After 10 attempts it seems to show that its trying to connect to a database inside the docker container.

error: Database Initialization Error: Access denied for user 'wikijs'@'172.17.0.3' (using password: YES)

Full Log

docker logs wiki
Loading configuration from /wiki/config.yml... OK
2020-05-27T18:45:56.214Z [MASTER] info: =======================================
2020-05-27T18:45:56.216Z [MASTER] info: = Wiki.js 2.3.81 ======================
2020-05-27T18:45:56.216Z [MASTER] info: =======================================
2020-05-27T18:45:56.216Z [MASTER] info: Initializing...
2020-05-27T18:45:56.618Z [MASTER] info: Using database driver mysql2 for mysql [ OK ]
2020-05-27T18:45:56.631Z [MASTER] info: Connecting to database...
2020-05-27T18:45:56.658Z [MASTER] error: Database Connection Error: ER_ACCESS_DENIED_ERROR undefined:undefined
2020-05-27T18:45:56.658Z [MASTER] warn: Will retry in 3 seconds... [Attempt 1 of 10]
2020-05-27T18:45:59.662Z [MASTER] info: Connecting to database...
2020-05-27T18:45:59.664Z [MASTER] error: Database Connection Error: ER_ACCESS_DENIED_ERROR undefined:undefined
2020-05-27T18:45:59.664Z [MASTER] warn: Will retry in 3 seconds... [Attempt 2 of 10]
2020-05-27T18:46:02.668Z [MASTER] info: Connecting to database...
2020-05-27T18:46:02.671Z [MASTER] error: Database Connection Error: ER_ACCESS_DENIED_ERROR undefined:undefined
2020-05-27T18:46:02.671Z [MASTER] warn: Will retry in 3 seconds... [Attempt 3 of 10]
2020-05-27T18:46:05.673Z [MASTER] info: Connecting to database...
2020-05-27T18:46:05.676Z [MASTER] error: Database Connection Error: ER_ACCESS_DENIED_ERROR undefined:undefined
2020-05-27T18:46:05.676Z [MASTER] warn: Will retry in 3 seconds... [Attempt 4 of 10]
2020-05-27T18:46:08.679Z [MASTER] info: Connecting to database...
2020-05-27T18:46:08.681Z [MASTER] error: Database Connection Error: ER_ACCESS_DENIED_ERROR undefined:undefined
2020-05-27T18:46:08.681Z [MASTER] warn: Will retry in 3 seconds... [Attempt 5 of 10]
2020-05-27T18:46:11.684Z [MASTER] info: Connecting to database...
2020-05-27T18:46:11.686Z [MASTER] error: Database Connection Error: ER_ACCESS_DENIED_ERROR undefined:undefined
2020-05-27T18:46:11.686Z [MASTER] warn: Will retry in 3 seconds... [Attempt 6 of 10]
2020-05-27T18:46:14.689Z [MASTER] info: Connecting to database...
2020-05-27T18:46:14.691Z [MASTER] error: Database Connection Error: ER_ACCESS_DENIED_ERROR undefined:undefined
2020-05-27T18:46:14.691Z [MASTER] warn: Will retry in 3 seconds... [Attempt 7 of 10]
2020-05-27T18:46:17.694Z [MASTER] info: Connecting to database...
2020-05-27T18:46:17.696Z [MASTER] error: Database Connection Error: ER_ACCESS_DENIED_ERROR undefined:undefined
2020-05-27T18:46:17.696Z [MASTER] warn: Will retry in 3 seconds... [Attempt 8 of 10]
2020-05-27T18:46:20.699Z [MASTER] info: Connecting to database...
2020-05-27T18:46:20.701Z [MASTER] error: Database Connection Error: ER_ACCESS_DENIED_ERROR undefined:undefined
2020-05-27T18:46:20.701Z [MASTER] warn: Will retry in 3 seconds... [Attempt 9 of 10]
2020-05-27T18:46:23.704Z [MASTER] info: Connecting to database...
2020-05-27T18:46:23.706Z [MASTER] error: Database Connection Error: ER_ACCESS_DENIED_ERROR undefined:undefined
2020-05-27T18:46:23.706Z [MASTER] warn: Will retry in 3 seconds... [Attempt 10 of 10]
2020-05-27T18:46:26.710Z [MASTER] info: Connecting to database...
2020-05-27T18:46:26.713Z [MASTER] error: Database Initialization Error: Access denied for user 'wikijs'@'172.17.0.3' (using password: YES)
Loading configuration from /wiki/config.yml... OK
2020-05-27T18:46:27.699Z [MASTER] info: =======================================
2020-05-27T18:46:27.701Z [MASTER] info: = Wiki.js 2.3.81 ======================
2020-05-27T18:46:27.701Z [MASTER] info: =======================================
2020-05-27T18:46:27.701Z [MASTER] info: Initializing...
2020-05-27T18:46:28.117Z [MASTER] info: Using database driver mysql2 for mysql [ OK ]
2020-05-27T18:46:28.122Z [MASTER] info: Connecting to database...
2020-05-27T18:46:28.147Z [MASTER] error: Database Connection Error: ER_ACCESS_DENIED_ERROR undefined:undefined
2020-05-27T18:46:28.148Z [MASTER] warn: Will retry in 3 seconds... [Attempt 1 of 10]

Host Info (please complete the following information): OS: Ubuntu 18.04, Docker Wiki.js version: 2.3.81 Database engine: mysql Ver 14.14 Distrib 5.7.30

Smankusors commented 4 years ago

Is your MySQL also a docker container? On the same host as Wiki.js docker container?

derek-shnosh commented 4 years ago

@Smankusors, MySQL is not in a docker container, but it is running on the Ubuntu server (VM) that the WikiJS docker container is on.

I'm doing something similiar with Bitwarden_RS, and have done this with WikiJS previously; seems maybe a version bump along the way changed something that broke this for WikiJS though.

NGPixel commented 4 years ago

You should be using 172.17.0.1 as the DB_HOST if you're trying to connect to a host MySQL server from within a docker container.

derek-shnosh commented 4 years ago

@NGPixel, I changed my docker run command as follows:

docker run -d --name wiki --restart unless-stopped -p 8081:3000 -e "DB_TYPE=mysql" -e "DB_HOST=172.17.0.1" -e "DB_PORT=3306" -e "DB_NAME=wikijs" -e "DB_USER=wikijs" -e "DB_PASS=ommitted" requarks/wiki:2

However I'm still getting the same error after 10 attemps:

error: Database Initialization Error: Access denied for user 'wikijs'@'172.17.0.3' (using password: YES)

I checked mysql privs for the wikijs user and found that it was only allowing login from localhost; the DB connection succeeded after making the appropriate adjustments and I am now looking at the install screen.