Skip to content
Advertisement

NodeJS ENOTFOUND db when connecting to MySQL container on docker

I am trying to connect From Node.js on Localhost to MySQL instance running on docker using docker-compose.

Node.js gives me this error: ENOTFOUND db, Full error message bellow.

JavaScript

Here is docker-compose.yml that contains MySQL and adminer services.

JavaScript

Here is my node.js database connection config.

JavaScript

Advertisement

Answer

You don’t tell us, but I assume your Node app is running on the host and not in a container? If that’s the case, then you need to expose the MySQL port to the host, so it’s reachable. You also need to use localhost as the hostname in your configuration.

Expose the port by changing the database part of your docker-compose file to

JavaScript

And change your Node configuration to

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement