Last active
October 28, 2024 08:02
-
-
Save chuyihuang/f4a062b964309e6cfc692aebe753d46d to your computer and use it in GitHub Desktop.
Dockerfile for Next.js example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Node environment | |
| NODE_ENV="development" | |
| POSTGRES_DB=mydatabase | |
| POSTGRES_USER=postgres | |
| POSTGRES_PASSWORD=password | |
| DATABASE_URL=postgresql://postgres:password@db:5432/mydatabase?schema=public | |
| NEXTAUTH_SECRET="aaaa1111wwwwddddffff" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Prisma 連線初始化 | |
| */ | |
| import { PrismaClient } from '@prisma/client'; | |
| const db = new PrismaClient(); | |
| export default db; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| services: | |
| app: | |
| build: | |
| context: . | |
| dockerfile: Dockerfile | |
| volumes: | |
| - .:/app | |
| - /app/node_modules | |
| ports: | |
| - "3000:3000" | |
| - "5432:5432" | |
| - "5555:5555" | |
| environment: | |
| - DATABASE_URL=${DATABASE_URL} | |
| env_file: | |
| - .env | |
| depends_on: | |
| - db | |
| db: | |
| image: postgres:latest | |
| environment: | |
| POSTGRES_DB: ${POSTGRES_DB} | |
| POSTGRES_USER: ${POSTGRES_USER} | |
| POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} | |
| volumes: | |
| - postgres-data:/var/lib/postgresql/data | |
| volumes: | |
| postgres-data: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 使用官方 Node.js 基礎映像 | |
| FROM node:20-alpine AS base | |
| FROM base AS deps | |
| # Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. | |
| RUN apk add --no-cache libc6-compat | |
| # 設置工作目錄 | |
| WORKDIR /app | |
| # 安装 pnpm | |
| RUN npm install -g pnpm | |
| # 複製 package.json 和 package-lock.json | |
| COPY package.json pnpm-lock.yaml* ./ | |
| # 安裝依賴 | |
| # 安装依赖 | |
| RUN pnpm install --frozen-lockfile | |
| COPY . . | |
| ENV GENERATE_SOURCEMAP false | |
| # 添加這一步來生成 Prisma Client | |
| RUN npx prisma generate | |
| # 啟動開發伺服器 | |
| CMD ["pnpm", "run", "dev"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| generator client { | |
| provider = "prisma-client-js" | |
| } | |
| datasource db { | |
| provider = "postgresql" | |
| url = env("DATABASE_URL") | |
| } | |
| model items { | |
| id Int @id @default(autoincrement()) | |
| item_no String @unique | |
| name String | |
| price Int | |
| created_at DateTime @default(now()) | |
| updated_at DateTime @updatedAt | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment