-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDockerfile
57 lines (40 loc) · 1.44 KB
/
Dockerfile
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
# --------- builder -----------
FROM node:20.14.0-alpine AS builder
WORKDIR /app
ARG proxy
ARG base_url
# copy common node_modules and one project node_modules
RUN [ -z "$proxy" ] || sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
COPY . .
RUN apk add --no-cache libc6-compat && npm install -g [email protected]
ENV NEXT_PUBLIC_BASE_URL=$base_url
RUN pnpm install --frozen-lockfile
RUN pnpm build
# --------- runner -----------
FROM node:20.14.0-alpine AS runner
WORKDIR /app
ARG proxy
ARG base_url
# create user and use it
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
RUN [ -z "$proxy" ] || sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
RUN apk add --no-cache curl ca-certificates \
&& update-ca-certificates
# copy running files
COPY --from=builder /app/public ./public
COPY --from=builder /app/next.config.js ./next.config.js
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static .next/static
# copy server chunks
COPY --from=builder --chown=nextjs:nodejs /app/.next/server/chunks .next/server/chunks
# copy package.json to version file
COPY --from=builder /app/package.json ./package.json
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
ENV PORT=3000
ENV NEXT_PUBLIC_BASE_URL=$base_url
EXPOSE 3000
USER nextjs
ENV serverPath=server.js
ENTRYPOINT ["sh","-c","node ${serverPath}"]