docker-compose.yml file
version: "3"
services:
mysql:
build: ./services/mysql
container_name: mysql
ports:
- ${MYSQL_PORT}:3306
volumes:
- ${MYSQL_DATA_PATH}:/var/lib/mysql:rw
- ./services/mysql/mysql.cnf:/etc/mysql/conf.d/mysql.cnf:ro
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
nodejs:
build: ./services/nodejs
container_name: nodejs
ports:
- ${NODE_PORT}:3000
links:
- mysql
depends_on:
- mysql
volumes:
- ./api:/var/www/html:rw
dockerfile of nodejs
FROM daocloud.io/library/node:11.6.0-alpine
WORKDIR /var/www/html
RUN npm config set unsafe-perm true
RUN npm config set registry https://registry.npm.taobao.org/
RUN npm install
RUN npm install -g pm2
CMD ./node_modules/.bin/sequelize db:migrate && npm start && pm2 list && pm2 logs
dockerfile file of mysql
FROM mysql:8.0
the problem now is that after mysql runs, nodejs also runs. When you go to . / node_modules/.bin/sequelize db:migrate
data migration, you will get an error because mysql is started, but the database initialization is not complete, so the connection is not successful.
I would like to ask you Daniel, is there any better solution?