-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
48 lines (35 loc) · 1020 Bytes
/
Copy pathDockerfile
File metadata and controls
48 lines (35 loc) · 1020 Bytes
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
# Stage 1: Dependencies
FROM node:18-alpine AS deps
WORKDIR /app
# Copy package.json and yarn.lock
COPY package.json ./
# Install dependencies
RUN yarn install --frozen-lockfile
# Stage 2: Build
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 yarn build
# Stage 3: Production
FROM node:18-alpine AS runner
WORKDIR /app
ENV NODE_ENV production
# Create a non-root user for security
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# Copy necessary files for running the app
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 the correct permission for nextjs user
USER nextjs
# Expose the listening port
EXPOSE 3000
# Set the environment variable for the port
ENV PORT 3000
# Run the application
CMD ["yarn", "start"]