NodeJS could not connect to MYSQL inside Docker Container

I've complied following docker-compose file, encounter error message.

version: '3'
services:
  node:
    build: ./app
    env_file:
      - ./.env
    ports:
      - "3000:3000"
    networks:
    - my-bridge-network
    depends_on:
      - "${MYSQL_HOST}"
  db:
    image: mysql:8.0.14
    env_file:
      - ./.env
    networks:
    - my-bridge-network
networks:
  my-bridge-network:
    driver: bridge

Here is configuration file for mysql sequelize,

{
    "production": {
        "username": "root",
        "password": "ppshein123456",
        "database": "database_production",
        "host": "0.0.0.0",
        "dialect": "mysql",
        "logging": false
    }
}

and Here is Dockerfile for NodeJS app,

FROM node:9.10.1
ENV NODE_ENV=development
COPY ./ /var/www
WORKDIR /var/www/
RUN yarn install && yarn add sequelize-cli -g
EXPOSE 3000
CMD /bin/bash ./wait-for-it.sh 127.0.0.1:3306 -- npm run docker

then, finally I encountered following error message:

Loaded configuration file "config/config.json". Using environment "production". Sat, 26 Jan 2019 01:03:45 GMT sequelize deprecated String based operators are now deprecated. Please use Symbol based operators for better security, read more athttp://docs.sequelizejs.com/manual/tutorial/querying.html#operators at node_modules/sequelize/lib/sequelize.js:242:13
ERROR: connect ECONNREFUSED 0.0.0.0:3306


#mysql #node-js #docker

4 Likes265.95 GEEK