Shubham Arya
Shubham Arya

Reputation: 135

db connection error node-mysql docker container

I've 2 container one of webapp(node) second of db(mysql) are in same docker network. But when running both container via docker compose, my app is not able to connect to database. Getting below error, when i check the webapp container logs.

Error connecting: Error: connect EHOSTUNREACH 172.28.0.2:3306 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1104:14)

NOTE: i am able to access the mysql container from docker host and also able to ping the mysql container from webapp(node ) container.

Please help, Thanks in advance.

Upvotes: 0

Views: 308

Answers (1)

Richa Bhuwania
Richa Bhuwania

Reputation: 180

Since both containers are running in the same network, try changing the HOST from 172.28.0.2:3306 to 127.0.0.1:3306.

Upvotes: 1

Related Questions