-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
executable file
·54 lines (39 loc) · 1.46 KB
/
Copy pathDockerfile
File metadata and controls
executable file
·54 lines (39 loc) · 1.46 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
53
54
# Production Dockerfile for Next.js with shadcn/ui
# Uses prebuilt base image for faster builds
# Build stage - uses base image with node_modules pre-installed
ARG BASE_IMAGE=node:22-slim
FROM ${BASE_IMAGE} AS builder
WORKDIR /app
# Copy package files first for better layer caching
COPY package*.json ./
# Install/update dependencies
# If base image has node_modules, npm install only adds new packages (fast)
# If no node_modules, does full install (slower but still works)
RUN npm install
# Copy source code
COPY . .
# Build the Next.js application (next.config.js already sets output: 'standalone')
ENV NEXT_TELEMETRY_DISABLED=1
ENV NODE_ENV=production
RUN npm run build
# Create public folder if it doesn't exist
RUN mkdir -p public
# Production image - minimal runtime (reuse base image to avoid re-downloading node)
FROM ${BASE_IMAGE} AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
# Create non-root user for security
RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 nextjs
# Copy standalone server (includes server.js and node_modules)
COPY --from=builder --chown=nextjs:nodejs /app/.next-build/standalone ./
# Copy static files to .next/static (required path for standalone server)
COPY --from=builder --chown=nextjs:nodejs /app/.next-build/static ./.next-build/static
# Copy public folder
COPY --from=builder /app/public ./public
USER nextjs
EXPOSE 3000
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
CMD ["node", "server.js"]