-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
48 lines (35 loc) · 1.47 KB
/
Copy pathDockerfile
File metadata and controls
48 lines (35 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# This file tells Docker how to build a container image for our app.
# It has two stages: first we build the app, then we copy just the
# finished result into a clean, smaller image to actually run it.
# ---------- STAGE 1: Build the app ----------
FROM node:20-alpine AS builder
# This is the folder inside the container where our files will live
WORKDIR /app
# Copy just the package files first. Docker is smart about caching --
# if these files don't change, it won't need to reinstall everything
# again next time we build.
COPY package.json package-lock.json* ./
# Install all the packages our app needs
RUN npm install
# Now copy the rest of our project files into the container
COPY . .
# Prisma needs this step to generate its database client before building
RUN npx prisma generate
# Build the Next.js app for production
RUN npm run build
# ---------- STAGE 2: Run the app ----------
# We start fresh with a clean, small image. We only copy over the
# finished build, not all our source code or dev dependencies.
FROM node:20-alpine AS runner
WORKDIR /app
# Tell Next.js it's running in production mode
ENV NODE_ENV=production
# Copy the built app from the first stage
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
COPY --from=builder /app/prisma ./prisma
# Our app listens on port 3000 inside the container
EXPOSE 3000
# This is the command that starts the app
CMD ["node", "server.js"]