When I build the container of the project with this command:
sudo docker build -t PROJECT_NAME .
And then I download the mysql's image through this Docker-Compose config:
db:
image: mysql
restart: always
ports:
- "8999:3306"
networks:
- webnet
environment:
MYSQL_DATABASE: slack
MYSQL_ROOT_PASSWORD: admin
And then, the project will connect with MySQL through the Sequelize ORM
I have this error:
Unhandled rejection SequelizeConnectionRefusedError: connect ECONNREFUSED 172.18.0.4:3306
How can I resolve this?
The Sequelize config is this:
const sequelize = new Sequelize(process.env.TEST_DB || 'slack', 'root', 'admin', {
host: process.env.DB_HOST || 'localhost',
operatorsAliases: Sequelize.Op,
dialect: 'mysql',
define: {
underscored: true
}
});
The config of the web is this:
web:
image: slack-clone-server
ports:
- "8080:8080"
networks:
- webnet
environment:
DB_HOST: db
REDIS_HOST: redis
command: ["./wait-for-it.sh", "db:3306", "--", "npm", "run", "prod"]
The script called "wait for it" is this.
If someone needs the complete code, here you go:
Sequelize config
Docker Compose config
Dockerfile config