I programmed a little nodejs app that connects to a mysql database with the following code lines.
const DATABASE = MYSQL.createPool({
host : 'localhost',
user : dbconfig.DATABASE_USER,
password: dbconfig.DATABASE_CREDENTIAL,
database: dbconfig.DATABASE_USING,
multipleStatements: true
});
When running the nodejs app with "yarn node server.js" everything works fine and the nodejs app connects to the mysql database over port 3306 (standard port).
Now I want to do the exact same thing with the only difference being: The Nodejs-App runs in a docker container exposed with the port 3300. Everytime I make an API-Call which triggers a query to the database the following error shows up:
(node:36) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:3306
at Object.createConnection (/app/.yarn/cache/mysql2-npm-2.2.5-fb26898147-2a3c2f0748.zip/node_modules/mysql2/promise.js:241:31)
at Function.Filling.getAllFillingLiter (/app/server/models/filling.model.js:59:28)
at Object.exports.getAllFillingLiter (/app/server/controller/filling.controller.js:36:13)
at /app/server.js:145:13
at Layer.handle [as handle_request] (/app/.yarn/cache/express-npm-4.17.1-6815ee6bf9-c4b470d623.zip/node_modules/express/lib/router/layer.js:95:5)
at next (/app/.yarn/cache/express-npm-4.17.1-6815ee6bf9-c4b470d623.zip/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/app/.yarn/cache/express-npm-4.17.1-6815ee6bf9-c4b470d623.zip/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/app/.yarn/cache/express-npm-4.17.1-6815ee6bf9-c4b470d623.zip/node_modules/express/lib/router/layer.js:95:5)
at /app/.yarn/cache/express-npm-4.17.1-6815ee6bf9-c4b470d623.zip/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/app/.yarn/cache/express-npm-4.17.1-6815ee6bf9-c4b470d623.zip/node_modules/express/lib/router/index.js:335:12)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:36) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:36) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
I honestly can't tell what I am doing wrong. The docker container should be able to connect to the mysql-database running on host right? But what is my mistake?
Thanks in advance