-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
81 lines (61 loc) · 2.46 KB
/
Copy pathDockerfile
File metadata and controls
81 lines (61 loc) · 2.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# syntax=docker/dockerfile:1.7
# ---------------------------------------------------------------
# WatchDocs - Multi-stage production image
# Image: watchdocs:1.0.0
# Port: 3355
# Output: Next.js standalone server
# ---------------------------------------------------------------
# ----- Stage 1: dependencies ---------------------------------------
FROM node:20-alpine AS deps
WORKDIR /app
# Enable corepack so pnpm is available without an extra install step
RUN corepack enable
# Copy only lockfiles to maximize Docker layer cache hits
COPY package.json pnpm-lock.yaml* package-lock.json* yarn.lock* ./
# Install dependencies using whichever lockfile is present
RUN \
if [ -f pnpm-lock.yaml ]; then pnpm install --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f yarn.lock ]; then yarn install --frozen-lockfile; \
else pnpm install; \
fi
# ----- Stage 2: build ----------------------------------------------
FROM node:20-alpine AS builder
WORKDIR /app
RUN corepack enable
# Bring in installed modules and source
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Disable Next.js telemetry at build time
ENV NEXT_TELEMETRY_DISABLED=1
# Build the Next.js app (produces .next/standalone when output: 'standalone')
RUN \
if [ -f pnpm-lock.yaml ]; then pnpm build; \
elif [ -f package-lock.json ]; then npm run build; \
elif [ -f yarn.lock ]; then yarn build; \
else pnpm build; \
fi
# ----- Stage 3: runner (slim production image) --------------------
FROM node:20-alpine AS runner
WORKDIR /app
# Production defaults
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
ENV PORT=3355
ENV HOSTNAME=0.0.0.0
# Create a non-root user so the app does not run as root
RUN addgroup --system --gid 1001 nodejs \
&& adduser --system --uid 1001 nextjs
# Copy the public directory (static assets served directly)
COPY --from=builder /app/public ./public
# Copy the standalone server and its required static chunks
# Ownership is assigned to the nextjs user for tighter permissions
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
USER nextjs
EXPOSE 3355
# Lightweight healthcheck - Next.js standalone answers on the root path
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://127.0.0.1:3355/ || exit 1
# server.js is generated by Next.js standalone output
CMD ["node", "server.js"]