Пол дня бьюсь, не выходит подключиться.
Поставил 3 пакета, adminer, mysql и node js. adminer нормально подключается к mysql. А вот нода падает с ошибкой
original: Error: connect ECONNREFUSED 172.27.0.3:3306
botapp-node-1 | at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1571:16) {
botapp-node-1 | errno: -111,
botapp-node-1 | code: 'ECONNREFUSED',
botapp-node-1 | syscall: 'connect',
botapp-node-1 | address: '172.27.0.3',
botapp-node-1 | port: 3306,
botapp-node-1 | fatal: true
botapp-node-1 | }
docker-compose
db:
build: ./db
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: 128Wh
volumes:
- ./save/db:/var/lib/mysql
ports:
- 3306:3306
adminer:
image: adminer
restart: always
ports:
- 7080:8080
node:
build: ./app
ports:
- 433:433
volumes:
- ./save/nodejs-app:/app
depends_on:
- db
environment:
MYSQL_HOST: db
Dockerfile в ноде
FROM node
WORKDIR /bot
COPY package.json /bot
RUN npm install
RUN npm install -g pm2
COPY . .
EXPOSE 433
CMD node index.js
Dockerfile в mysql
FROM mysql
EXPOSE 3306
Сам код подключения
const { Sequelize, Op } = require('sequelize');
const dataConnect = {
host: process.env.MYSQL_HOST,
name: 'passports',
user: 'root',
password: '128Wh',
};
const sequelize = new Sequelize(dataConnect.name, dataConnect.user, dataConnect.password, {
dialect: 'mysql',
host: dataConnect.host,
});
try {
sequelize.authenticate();
console.log('Connection has been established successfully.');
} catch (error) {
console.error('Unable to connect to the database:', error);
}