I'm currently trying to learn docker. What i'm trying to achieve is deploy my fullstack next js + prisma + mysql. The main problem I'm encountering is, even though I created the database, the tables are not being created. I've tried searching but I'm being overwhelm.
Dockerfile
FROM node
WORKDIR /app
COPY package*.json ./
COPY prisma ./prisma
RUN npm install
RUN npx prisma generate && npx prisma db push
COPY . .
EXPOSE 3000
CMD npm run dev
compose.yml
version: '3.8'
services:
frontend:
build:
context: .
dockerfile: Dockerfile
ports:
- 3000:3000
develop:
watch:
- path: ./package.json
action: rebuild
- path: ./next.config.js
action: rebuild
- path: './package-lock.json'
action: rebuild
- path: .
target: /app
action: sync
environment:
- NODE_ENV=development
- DATABASE_URL=mysql://root:admin@db:3307/next-sched
depends_on:
db:
condition: service_healthy
volumes:
- .:/app
- /app/node_modules
- /app/.next
db:
image: mysql:8.0
ports:
- 3307:3306
environment:
- MYSQL_ROOT=root
- MYSQL_ROOT_PASSWORD=admin
- MYSQL_DATABASE=next-sched
volumes:
- mysql-data:/var/lib/mysql
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "db"]
timeout: 20s
retries: 10
restart: unless-stopped
volumes:
mysql-data:
.env
DATABASE_URL="mysql://root:admin@localhost:3307/next-sched"
schema.prisma
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
//the rest of code
so when I run docker compse up. It creates the database but there are no tables.