-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathDockerfile
56 lines (39 loc) · 1.25 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
46
47
48
49
50
51
52
53
54
55
56
FROM node:18-alpine AS deps
WORKDIR /app
# Copy package files for dependency installation
COPY package.json package-lock.json .npmrc ./
# Install dependencies with specific npm configuration
RUN npm ci
# Build stage
FROM node:18-alpine AS builder
WORKDIR /app
# Copy dependencies from deps stage
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Build the application
RUN npm run build
# Production stage
FROM node:18-alpine AS runner
WORKDIR /app
# Set environment to production
ENV NODE_ENV=production
# Create a non-root user for security
RUN addgroup --system --gid 1001 nodejs \
&& adduser --system --uid 1001 nextjs
# Copy necessary files from builder
COPY --from=builder /app/next.config.cjs ./
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json
# Set proper permissions
RUN chown -R nextjs:nodejs /app
# Use the non-root user
USER nextjs
# Expose the port the app runs on
EXPOSE 3000
# Add healthcheck
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/ || exit 1
# Start the application
CMD ["npm", "run", "start"]