'How do npx sequelize-cli db:migrate in dockerfile?
I can't do npx sequelize-cli db:migrate when build my app. I need creat docker-compose wthi DB and bot. But DB created empty, and I want creat table. When I do this wihtout docer, I use npx sequelize-cli db:migrate.
My Dockerfile:
FROM node:14
WORKDIR /usr/src/app
#Install app dependencies
COPY package*.json ./
COPY . .
RUN npm install
RUN npx sequelize db:migrate
EXPOSE 6432
CMD [ "node", "src/bot.js" ]
My docker-compose.yml:
version: "3.9" # optional since v1.27.0
services:
db:
image: postgres
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=post123
- POSTGRES_DB=bot-db
ports:
- "6432:5432"
bot:
build: .
env_file: .env
environment:
- BOT_TOKEN=$BOT_TOKEN
- POSTGRES_USERNAME=$POSTGRES_USERNAME
- POSTGRES_PASSWORD=$POSTGRES_PASSWORD
- POSTGRES_NAME=$POSTGRES_NAME
- POSTGRES_HOST=db
- POSTGRES_PORT=5432
- POSTGRES_DIALECT=$POSTGRES_DIALECT
ports:
- "49160:8080"
links:
- db
I will do: docker-compose up
But:
Building bot
[+] Building 10.3s (10/10) FINISHED
=> [internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 235B 0.0s
=> [internal] load .dockerignore 0.1s
=> => transferring context: 34B 0.0s
=> [internal] load metadata for docker.io/library/node:14 2.0s
=> [1/6] FROM docker.io/library/node:14@sha256:50d4540794db9bdbd423a5823c4d840fc2ba0b9c82d71b059ff34b4aeb3e328f 0.0s
=> [internal] load build context 0.1s
=> => transferring context: 13.94kB 0.0s
=> CACHED [2/6] WORKDIR /usr/src/app 0.0s
=> CACHED [3/6] COPY package*.json ./ 0.0s
=> [4/6] COPY . . 0.1s
=> [5/6] RUN npm install 7.0s
=> ERROR [6/6] RUN npx sequelize db:migrate 1.0s
------
> [6/6] RUN npx sequelize db:migrate:
#10 0.909
#10 0.909 Sequelize CLI [Node: 14.18.3, CLI: 6.3.0, ORM: 6.13.0]
#10 0.909
#10 0.935 Loaded configuration file "src/sequelize-config.js".
#10 0.935 Using environment "development".
#10 0.936
#10 0.936 ERROR: Dialect needs to be explicitly supplied as of v4.0.0
#10 0.937
------
executor failed running [/bin/sh -c npx sequelize db:migrate]: exit code: 1
ERROR: Service 'bot' failed to build : Build failed
All work in local, but dosent work in docker.
How to fix it?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
