Skip to content

Commit c9ce19c

Browse files
committed
update docker file
1 parent b4d68e3 commit c9ce19c

File tree

4 files changed

+55
-34
lines changed

4 files changed

+55
-34
lines changed

Dockerfile

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,64 @@
1-
FROM node:22.12.0-alpine3.19 AS builder
1+
## exmaple: https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile
2+
FROM node:22.12.0-alpine3.19 AS base
3+
4+
# Install dependencies only when needed
5+
FROM base AS deps
6+
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
7+
RUN apk add --no-cache libc6-compat
28
WORKDIR /app
39

4-
COPY package*.json ./
10+
# set mirror for npm
11+
# RUN npm config set registry https://registry.npmmirror.com
12+
13+
# RUN apt-get update && apt-get install -y python3 python3-pip build-essential
14+
# RUN ln -s /usr/bin/python3 /usr/bin/python
515

6-
RUN npm ci
16+
# Install dependencies based on the preferred package manager
17+
COPY ./package*.json ./
18+
RUN npm install
19+
20+
# Rebuild the source code only when needed
21+
FROM base AS builder
22+
WORKDIR /app
23+
COPY --from=deps /app/node_modules ./node_modules
24+
COPY ./ .
725

8-
COPY . .
26+
# Next.js collects completely anonymous telemetry data about general usage.
27+
# Learn more here: https://nextjs.org/telemetry
28+
# Uncomment the following line in case you want to disable telemetry during the build.
29+
ENV NEXT_TELEMETRY_DISABLED=1
930

1031
RUN npm run build
1132

33+
# Production image, copy all the files and run next
34+
FROM base AS runner
35+
WORKDIR /app
1236

37+
ENV NODE_ENV=production
38+
# Uncomment the following line in case you want to disable telemetry during runtime.
39+
ENV NEXT_TELEMETRY_DISABLED=1
1340

41+
RUN addgroup --system --gid 1001 nodejs
42+
RUN adduser --system --uid 1001 nextjs
1443

44+
COPY --from=builder /app/public ./public
1545

16-
# 使用轻量级的 Node.js 镜像
17-
FROM node:22.12.0-alpine3.19 AS runner
46+
# Set the correct permission for prerender cache
47+
RUN mkdir .next
48+
RUN chown nextjs:nodejs .next
1849

19-
# 设置工作目录
20-
WORKDIR /app
50+
# Automatically leverage output traces to reduce image size
51+
# https://nextjs.org/docs/advanced-features/output-file-tracing
52+
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
53+
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
2154

22-
# 复制构建好的文件
23-
COPY --from=builder /app ./
55+
USER nextjs
2456

25-
# 暴露应用运行的端口
2657
EXPOSE 3000
2758

28-
# 启动应用
29-
CMD ["npm", "start"]
59+
ENV PORT=3000
60+
61+
# server.js is created by next build from the standalone output
62+
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
63+
ENV HOSTNAME="0.0.0.0"
64+
CMD ["node", "server.js"]

app/lib/db.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

next.config.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
// next.config.mjs
44
export default {
5+
output: "standalone",
6+
reactStrictMode: true,
57
async redirects() {
68
return [
79
{

package.json

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,18 @@
1111
"@fortawesome/react-fontawesome": "^0.2.2",
1212
"@heroicons/react": "^2.2.0",
1313
"@tailwindcss/forms": "^0.5.7",
14-
"@vercel/postgres": "^0.10.0",
15-
"antd": "^5.22.3",
14+
"antd": "^5.22.4",
1615
"autoprefixer": "10.4.20",
17-
"bcrypt": "^5.1.1",
1816
"clsx": "^2.1.1",
1917
"d3": "^7.9.0",
20-
"next": "^15.0.4",
21-
"next-auth": "4.24.10",
22-
"pg": "^8.12.0",
18+
"next": "^15.1.0",
19+
"next-auth": "4.24.11",
2320
"postcss": "8.4.49",
2421
"react": "18.3.1",
2522
"react-dom": "18.3.1",
2623
"tailwindcss": "3.4.16",
2724
"typescript": "5.7.2",
28-
"use-debounce": "^10.0.1",
29-
"zod": "^3.23.8"
25+
"use-debounce": "^10.0.1"
3026
},
3127
"devDependencies": {
3228
"@types/bcrypt": "^5.0.2",
@@ -35,7 +31,7 @@
3531
"@types/react": "18.3.12",
3632
"@types/react-dom": "18.3.1",
3733
"eslint": "9.16.0",
38-
"eslint-config-next": "^15.0.4"
34+
"eslint-config-next": "^15.1.0"
3935
},
4036
"engines": {
4137
"node": ">=20.12.0"

0 commit comments

Comments
 (0)