-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
40 lines (29 loc) · 976 Bytes
/
Dockerfile
File metadata and controls
40 lines (29 loc) · 976 Bytes
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
# --- Stage 1: Build the Next.js App ---
FROM node:20 AS builder
ARG NEXT_PUBLIC_RECAPTCHA_SITE_KEY
ENV NEXT_PUBLIC_RECAPTCHA_SITE_KEY=${NEXT_PUBLIC_RECAPTCHA_SITE_KEY}
# Set working directory inside the container
WORKDIR /app
# Copy package.json and package-lock.json (if available)
COPY package.json package-lock.json* ./
# Install dependencies
RUN npm install --frozen-lockfile
# Copy the rest of the project files
COPY . .
# Build the Next.js app
RUN npm run build
# --- Stage 2: Run the Next.js App ---
FROM node:20 AS runner
# Set environment variables
ENV NODE_ENV=production
# Set working directory inside the container
WORKDIR /app
# Copy built files from the builder stage
COPY --from=builder /app/.next .next
COPY --from=builder /app/public public
COPY --from=builder /app/package.json package.json
COPY --from=builder /app/node_modules node_modules
# Expose port 3000 for the app
EXPOSE 3000
# Run Next.js in production mode
CMD ["npm", "run", "start"]