-
-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathDockerfile
More file actions
70 lines (49 loc) · 1.64 KB
/
Dockerfile
File metadata and controls
70 lines (49 loc) · 1.64 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Dependencies stage
FROM node:20-slim AS deps
WORKDIR /app
# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
python3 \
make \
g++ \
&& rm -rf /var/lib/apt/lists/*
# Install corepack and pnpm
RUN corepack enable && corepack prepare pnpm@8.15.4 --activate
# Copy package files
COPY package.json pnpm-lock.yaml* .npmrc* ./
# Install dependencies
RUN pnpm install --frozen-lockfile
# Builder stage
FROM node:20-slim AS builder
WORKDIR /app
RUN corepack enable && corepack prepare pnpm@8.15.4 --activate
# Copy dependencies and source
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Build application
ENV NEXT_TELEMETRY_DISABLED=1
RUN pnpm build
# Production stage
FROM node:20-slim AS runner
WORKDIR /app
ENV NODE_ENV=production \
NEXT_TELEMETRY_DISABLED=1
# Install wget for healthcheck
RUN apt-get update && apt-get install -y --no-install-recommends \
wget \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user
RUN groupadd -r nodejs --gid=1001 && \
useradd -r -g nodejs --uid=1001 nextjs
# Copy built application
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
COPY --from=builder --chown=nextjs:nodejs /app/next.config.js ./
COPY --from=builder --chown=nextjs:nodejs /app/package.json ./
COPY --from=builder --chown=nextjs:nodejs /app/node_modules ./node_modules
USER nextjs
EXPOSE 3000
ENV PORT=3000
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/ || exit 1
CMD ["node_modules/.bin/next", "start"]