1

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

version: '3'
services:
  node:
    build: ./app
    environment:
      - NODE_ENV=production
      - PORT=3000
      - MYSQL_HOST=ppshein-mysql
      - MYSQL_USER=root
      - MYSQL_PASSWORD=ppshein123456
    ports:
      - "3000:3000"
    networks:
    - my-bridge-network
    depends_on:
      - "${MYSQL_HOST}"
    container_name: ppshein-api
  db:
    image: mysql:8.0.14
    environment:
      - MYSQL_ROOT_PASSWORD=ppshein123456
    networks:
    - my-bridge-network
    container_name: ppshein-mysql
networks:
  my-bridge-network:
    driver: bridge

Here is configuration file for mysql sequelize,

"production": {
    "username": "root",
    "password": "ppshein123456",
    "database": "database_production",
    "host": "ppshein-mysql",
    "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 ppshein-mysql: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 at http://docs.sequelizejs.com/manual/tutorial/querying.html#operators at node_modules/sequelize/lib/sequelize.js:242:13

ERROR: connect ECONNREFUSED 172.21.0.2:3306

PPShein
  • 13,309
  • 42
  • 142
  • 227

1 Answers1

2

You should not access MySQL on 0.0.0.0.

Docker-compose define hostnames for containers on same bridge network equals to the container name, so your MySQL hostname is db.

If you want to customize your container hostname, you can do it using aliases on network. Please see this answer: https://stackoverflow.com/a/47264089/3429323

Elias Soares
  • 9,884
  • 4
  • 29
  • 59