-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
35 lines (25 loc) · 850 Bytes
/
Dockerfile
File metadata and controls
35 lines (25 loc) · 850 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
# 1. Use the official Node.js LTS image
FROM node:20-alpine AS base
# 2. Set working directory inside container
WORKDIR /app
# 3. Copy package.json and package-lock.json first
COPY package.json package-lock.json ./
# 4. Install only production dependencies
RUN npm install --only=production
# 5. Copy the rest of your application code
COPY . .
# 6. Build the Next.js app
RUN npm run build
# 7. Create a smaller production image
FROM node:20-alpine AS runner
# 8. Set working directory
WORKDIR /app
# 9. Copy built assets and node_modules from previous stage
COPY --from=base /app/public ./public
COPY --from=base /app/.next ./.next
COPY --from=base /app/node_modules ./node_modules
COPY --from=base /app/package.json ./package.json
# 10. Set environment to production
ENV NODE_ENV=production
# 11. Start the app
CMD ["npm", "run", "start"]