-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockerfile
45 lines (33 loc) · 1.11 KB
/
Dockerfile
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
# 1. Use the specific Node.js version as the base image
FROM node:20.11.0 AS builder
# 2. Set working directory inside the container
WORKDIR /app
# 3. Copy package.json and package-lock.json
COPY package*.json ./
# 4. Install dependencies using the specified npm version
RUN npm install -g [email protected] && npm install
# 5. Copy all application files
COPY . .
ARG NEXT_PUBLIC_SERVER_URI
ARG NEXT_PUBLIC_NEXTAUTH_URL
ARG NEXTAUTH_URL
# 6. Build the Next.js app
RUN NEXT_PUBLIC_SERVER_URI=$NEXT_PUBLIC_SERVER_URI \
NEXTAUTH_URL=$NEXTAUTH_URL \
NEXT_PUBLIC_NEXTAUTH_URL=$NEXT_PUBLIC_NEXTAUTH_URL \
npm run build
# 7. Production image
FROM node:20.11.0 AS production
# 8. Set working directory inside the production container
WORKDIR /app
# 9. Copy only the necessary files from the builder stage
COPY --from=builder /app/package*.json ./
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
COPY --from=builder /app/node_modules ./node_modules
# 10. Environment variable for production
ENV NODE_ENV=production
# 11. Expose the port
EXPOSE 3000
# 12. Start the Next.js app
CMD ["npm", "start"]