-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdockerfile.example
More file actions
43 lines (30 loc) · 1.36 KB
/
dockerfile.example
File metadata and controls
43 lines (30 loc) · 1.36 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
# Category: Prod
# Service: Docker NodeJS Production Dockerfile
# Description: Production-ready Dockerfile for building and serving the Next.js application.
# Maintainer: ryumada
FROM node:${DOCKER_NODEJS_TAG} AS builder
USER node
WORKDIR /usr/src/app
# Hardening: Set production environment and disable Next.js telemetry
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
COPY --chown=node:node app/${APP_NAME}/package.json app/${APP_NAME}/package-lock.json ./
RUN npm ci
COPY --chown=node:node app/${APP_NAME} ./
RUN npm run build
# STAGE 2: Serve the Next.js application with a production-ready environment
FROM node:${DOCKER_NODEJS_TAG} AS runner
USER node
WORKDIR /usr/src/app
# Hardening: Set production environment and disable Next.js telemetry
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
# Copy only necessary files from the builder stage
COPY --from=builder --chown=node:node /usr/src/app/.next ./.next
COPY --from=builder --chown=node:node /usr/src/app/node_modules ./node_modules
COPY --from=builder --chown=node:node /usr/src/app/public ./public
COPY --from=builder --chown=node:node /usr/src/app/package.json ./package.json
COPY --from=builder --chown=node:node /usr/src/app/next.config.mjs ./next.config.mjs
EXPOSE 3000
# Start the application directly to ensure OS signals are passed for graceful shutdowns
CMD ["./node_modules/.bin/next", "start"]