I have been having troubles reaching mysql server from my dockarized nodejs app. I can access the database normally with localhost, port 3307, password, user and database
in workbenceh so I assumed I can just do the same in my nodejs app but with 3306.
No matter what configuration I have tried I've always gotten the -111, ECONNREFUSED, connect... error back.
Mysql server is ready for connections before nodejs starts and is listening on 3306. I have the right users with the right privelages... I really don't know what I am missing at this point.
version: '3.3'
services:
db:
image: mysql:8
restart: always
volumes:
- db:/var/lib/mysql
env_file: ./.env
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: database
MYSQL_ROOT_USER: user
ports:
- 3307:3306
app:
container_name: app_con
build: ./
restart: always
env_file: ./.env
ports:
- 5000:5000
stdin_open: true
tty: true
depends_on:
- db
volumes:
db:
My node.js connection:
const pool = mysql.createPool({
connectionLimit: 15,
host: localhost, /*I have tried 127.0.0.1, 0.0.0.0, 172..., my lan ip*/
user: user,
password: password,
port: 3306, /*I have also tried 3307*/
database: database,
multipleStatements: true
});