-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathDockerfile
More file actions
51 lines (35 loc) · 1.01 KB
/
Dockerfile
File metadata and controls
51 lines (35 loc) · 1.01 KB
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
# Stage 1: Dependencies and Build
FROM node:18-alpine AS builder
# Set working directory
WORKDIR /app
# Copy package files for dependency installation
COPY package.json package-lock.json* ./
# Install dependencies
RUN npm ci
# Copy all project files
COPY . .
# Build the application
RUN npm run build
# Stage 2: Production image
FROM node:18-alpine AS runner
WORKDIR /app
# Set environment to production
ENV NODE_ENV production
# Create a non-root user to run the app
RUN addgroup --system --gid 1001 nodejs \
&& adduser --system --uid 1001 nextjs
# Copy only necessary files from the builder stage
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
# Set the correct permissions
RUN chown -R nextjs:nodejs /app
# Switch to non-root user
USER nextjs
# Expose the port the app will run on
EXPOSE 3000
# Set the correct environment variables for Next.js
ENV PORT 3000
ENV HOSTNAME "0.0.0.0"
# Start the app
CMD ["node", "server.js"]