Can't get connected to mysql db using sequelize and docker

I am trying to connect to Mysql database using docker-compose in node.js

ConnectionRefusedError [SequelizeConnectionRefusedError]: connect ECONNREFUSED

here is how my docker-compose.yml looks like

version: '3.9'

    image: 'mysql'
      - '3306:3306'
    restart: always
      MYSQL_ROOT_PASSWORD: 12345678
      MYSQL_DATABASE: sweeft
      MYSQL_USER: sweeft_user
      MYSQL_PASSWORD: 12345678

    build: .
      - '3000:3000'
      - db
      DB_HOST: db
      DB_USER: sweeft_user
      DB_PASSWORD: 12345678
      DB_NAME: sweeft

I am trying to connect like this

import Sequelize from 'sequelize';

const sequelize = new Sequelize('sweeft', 'sweeft_user', 12345678, {
  host: 'db',
  dialect: 'mysql',

export default sequelize;

error I am getting in the Docker Desktop

When you start multiple services in Docker compose, they are usually attached to a default Docker network. Your server app should connect within the Docker network to db, you do not need to expose ports on the db service.

But the mentioned IP 192.x.x.x seems strange, Docker networks usually have a different IP range. Have you tried setting up a dedicated Docker network and attaching both services? See simple Traefik example.

No, I have not tried I’ll try it, one thing to note is that on every new build, I get new IP for example

Now that looks like a Docker network IP :slightly_smiling_face: