-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathDockerfile
46 lines (33 loc) · 912 Bytes
/
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
# Build stage
FROM node:alpine AS builder
# Set working directory
WORKDIR /app
# Copy package files
COPY package.json yarn.lock ./
# Install dependencies
RUN yarn install --frozen-lockfile
# Copy source files
COPY . .
# Build application
RUN yarn build
# Production stage
FROM node:alpine AS runner
WORKDIR /app
# Set environment to production
ENV NODE_ENV production
# Copy necessary files from builder
COPY --from=builder /app/next.config.js ./
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
# Create a non-root user
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
RUN chown -R nextjs:nodejs /app
# Switch to non-root user
USER nextjs
# Expose the port the app runs on
EXPOSE 3000
# Start the application
CMD ["yarn", "start"]