0

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Same errror is there: at FSReqWrap.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:53:3) Error connecting: Error: connect ECONNREFUSED 127.0.0.1:3306 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1104:14)
Have you tried it without docker? Is it working fine? What is the configuration?
Yes it works fine without docker, and this is my compose file: version: "3.2" services: mysql_db: build: ./db ports: - "6603:3306" environment: - DATABASE_HOST= mysql_db - MYSQL_ROOT_PASSWORD=*** - MYSQL_USER=**** - MYSQL_PASSWORD=*** - MYSQL_DATABASE=**** container_name: db_cont networks: - my_net restart: always nodejs_app: build: ./web depends_on: - mysql_db container_name: app_cont1 networks: - my_net ports: - "3035:3035" networks: my_net:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.