-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.prod
More file actions
52 lines (39 loc) · 1.35 KB
/
Dockerfile.prod
File metadata and controls
52 lines (39 loc) · 1.35 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
52
# Stage 1: Builder (all dependencies)
# preferred node version chosen here (Active LTS = 22 as of 10/2024)
FROM public.ecr.aws/docker/library/node:22.22-alpine3.23 AS builder
WORKDIR /app
# Copy dependencies from deps stage
COPY package*.json ./
RUN npm ci
COPY . .
# Set production environment
ENV NEXT_TELEMETRY_DISABLED 1
ENV NODE_ENV=production
# Set environment variables
ENV NEXT_PUBLIC_SERVER_ENDPOINT=$NEXT_PUBLIC_SERVER_ENDPOINT
ENV NEXT_PUBLIC_BASE_URL=$NEXT_PUBLIC_BASE_URL
# Build the application
RUN npm run build
RUN npm prune --omit=dev
# Stage 2: Runner
FROM public.ecr.aws/docker/library/node:22.1.0-alpine3.19 AS runner
WORKDIR /app
# Install bash so we can use session manager to attach to the container
# and perform container health checks
RUN apk add --no-cache bash curl
# Set production environment
ENV NEXT_TELEMETRY_DISABLED 1
ENV NODE_ENV=production
# Create non-root user
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# Copy necessary files
COPY --from=builder /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
#Switch to non-root user
USER nextjs
# Ensure port 3000 is accessible to our system
EXPOSE 3000
# Start the application
CMD ["node", "server.js", "--hostname", "0.0.0.0", "--port", "3000"]