File size: 915 Bytes
6ba7c23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e46f68d
 
0454be9
d0e894b
ae37a50
 
6ba7c23
e46f68d
473188a
8404cde
9345ff8
 
e46f68d
 
6ba7c23
d0e894b
 
 
e46f68d
6ba7c23
 
d0e894b
 
 
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 application
FROM node:20-alpine AS builder
RUN apk add --no-cache libc6-compat
WORKDIR /app

# Install dependencies
COPY frontend/package.json frontend/package-lock.json ./
RUN npm install

# Copy source files and build the Next.js application
COPY frontend ./
RUN npm run build

# Install PM2 globally
RUN npm install -g pm2

# Stage 2: Run the Next.js application with PM2
FROM node:20-alpine

# Create necessary directories with write permissions
WORKDIR /tmp
RUN mkdir -p /tmp/app/.next/cache/images && chown -R node:node /tmp/app/.next/cache/images

# Copy the Next.js build and node_modules from the builder stage
COPY --from=builder /app /tmp/app

WORKDIR /tmp/app

# Install PM2 globally
RUN npm install -g pm2

# Set environment variables
ENV PORT=7860

# Expose port 7860
EXPOSE 7860

# Run the application with PM2
USER node
CMD ["pm2-runtime", "start", "npm", "--", "start"]