ChandimaPrabath commited on
Commit
35877e1
·
verified ·
1 Parent(s): c811ef2

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +43 -0
Dockerfile ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Stage 1: Build the Next.js application
2
+ FROM node:20-alpine AS builder
3
+ RUN apk add --no-cache libc6-compat
4
+ WORKDIR /app
5
+
6
+ # Install dependencies
7
+ COPY frontend/package.json frontend/package-lock.json ./
8
+ RUN npm install
9
+
10
+ # Copy source files and build the Next.js application
11
+ COPY frontend ./
12
+ RUN npm run build
13
+
14
+ # Install PM2 globally
15
+ RUN npm install -g pm2
16
+
17
+ # Stage 2: Run the Next.js application with PM2
18
+ FROM node:20-alpine
19
+
20
+ # Create necessary directories with write permissions
21
+ WORKDIR /tmp
22
+ RUN mkdir -p /tmp/app/.next/cache/images /tmp/app/.next/cache/fetch-cache
23
+
24
+ # Copy the Next.js build and node_modules from the builder stage
25
+ COPY --from=builder /app /tmp/app
26
+
27
+ WORKDIR /tmp/app
28
+
29
+ # Change ownership of the /tmp/app directory to the node user
30
+ RUN chown -R node:node /tmp/app
31
+
32
+ # Install PM2 globally
33
+ RUN npm install -g pm2
34
+
35
+ # Set environment variables
36
+ ENV PORT=7860
37
+
38
+ # Expose port 7860
39
+ EXPOSE 7860
40
+
41
+ # Run the application with PM2
42
+ USER node
43
+ CMD ["pm2-runtime", "start", "npm", "--", "start"]