I have created a NodeJS app and built an image and ran it. In that container app, I am trying to access the MySQL database from localhost (MySQL is in the host). But, when I try to access it, I am getting the following error
I have looked for so many solutions from StackOverflow and other resources. But, couldn't solve the issue. Even I tried to grant access to user root from all the hosts using the below
CREATE USER 'root'@'%' IDENTIFIED BY 'passw0rd';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
Still, I am facing the same issue.
Docker file:
FROM node:14
WORKDIR /usr/testapp
COPY package*.json ./
RUN npm install && npm install typescript -g
COPY . .
RUN tsc
CMD [ "node", "./dist/app.js" ]
Can you please help me solve this issue?
Thank you...
EDIT:
ormconfig.json
{
"type": "mysql",
"host": "localhost",
"port": 3306,
"username": "root",
"password": "passw0rd",
"database": "hostelme",
"synchronize": true,
"logging": false,
"entities": [
"src/entity/**/*.ts"
],
...
}
Commands to build and run the container:
docker build -t hnb-app . # To build
docker run -p 3000:3000 hnb-app # To run