I am getting below error while running npx sequelize db:migrate
Sequelize CLI [Node: 16.14.0, CLI: 6.4.1, ORM: 6.12.5]
node_api |
node_api |
node_api |
node_api | ERROR: Cannot find "/app/src/config/database.js". Have you run "sequelize init"?
Dockerfile of node-app
FROM node:16.14.0-alpine
ENV WORK_DIR /app
WORKDIR $WORK_DIR
COPY . .
RUN npm install && npm cache clean --force
EXPOSE 8080
#CMD [ "npm", "run", "dev" ]
added below node api container in Docker-compose file like below:
api:
container_name: node_api
build:
context: ../node-app/
dockerfile: Dockerfile.dev
ports:
- 8080:8080
depends_on:
- postgres
restart: on-failure
volumes:
- ../node-app/:/app/src
command: sh -c "cd src && npx sequelize db:migrate --config config/database.js && npm run dev"
environment:
# Port
PORT: 8080
# Debug
LOG_LEVEL: debug
DB_USERNAME: postgres
DB_PASSWORD: root
DB_NAME: mydb
DB_HOSTNAME: postgres_db
DB_PORT: 5432
NODE_ENV: development
I have kept .sequelizerc file inside src folder having below content.
const path = require('path');
module.exports = {
'config': path.resolve('config', 'database.js'),
'models-path': path.resolve('db', 'models'),
'seeders-path': path.resolve('db', 'seeders'),
'migrations-path': path.resolve('db', 'migrations')
};
When I run sequelize command src directory inside node-app, it works properly and migration happens. But when I run it from docker it cannot find .sequelizerc file which is kept in src folder only. To avoid confusion I gave database.js path to sequelize command still I am getting error that file not found.
This is weird problem I am facing. I have wild guess that there is some issue with versions of sequelize, nodejs and cli.
Let me know anyone can help me in finding my mistake. Thanks in advance.
CodePudding user response:
The issue is with the volume mount.
volumes:
- ../node-app/:/app/src