0

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.

1 Answer 1

1

The issue is with the volume mount.

    volumes:
      - ../node-app/:/app/src
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks @pratheesh it worked. But I am still thinking that everything is in src folder so that should not cause problem.
That option hides the /app/src directory from the image and replaces it with different content; so you're running fundamentally different code from what's packaged in the image, possibly with a different directory layout. I'd suggest deleting this block as well.
@DavidMaze I changed this to correct one like as ../node-app/:/app/ So that working code can match properly and node server restarts as soon as I do changes in code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.