From daa22f8ff98a40944bbaa863fa492f7b7a30f5c9 Mon Sep 17 00:00:00 2001 From: R2m1liA <15258427350@163.com> Date: Wed, 5 Nov 2025 13:09:25 +0800 Subject: [PATCH] =?UTF-8?q?build:=20=E6=B7=BB=E5=8A=A0Dockerfile=E7=94=A8?= =?UTF-8?q?=E4=BA=8E=E6=9E=84=E5=BB=BAdocker=E9=95=9C=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 基于node:22-alpine构建docker镜像 --- .dockerignore | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 41 ++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9f75435 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,58 @@ +# ------------------------ +# Node / Package Manager +# ------------------------ +node_modules +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +.pnpm-store + +# Nuxt build outputs +.output +.nuxt +dist +.cache +.unimport +.h3 +.nitro +**/.nitro + +# Dev tools / OS files +.DS_Store +Thumbs.db + +# Logs +*.log +logs +!.gitkeep + +# Local env files (runtime env should be provided by Docker/K8s) +.env +.env.* +!.env.example + +# Git +.git +.gitignore +.gitattributes + +# Editor / IDE +.vscode +.idea +*.swp +*.swo + +# Tests +coverage +*.lcov + +# Docker +Dockerfile* +docker-compose.yml + +# CI / Local build artifacts +*.tgz +*.zip +*.tar +*.mdx diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f8876aa --- /dev/null +++ b/Dockerfile @@ -0,0 +1,41 @@ + -------- Base image -------- +FROM node:22-alpine AS base +ENV NODE_ENV=production +WORKDIR /app + +# -------- Dependencies layer ------- +FROM base AS deps +WORKDIR /app + +RUN corepack enable + +# Copy package.json and lockfile +COPY package.json pnpm-lock.yaml .npmrc ./ + +# Install dependencies with cache +RUN --mount=type=cache,target=/root/.local/share/pnpm/store pnpm install + +# -------- Build layer ------- +FROM deps AS build +# Copy entire project +COPY . ./ + +ENV NITRO_PRESET=node-server + +# Build the project +RUN pnpm run build + +# ------- Runtime layer ------- +FROM base AS runtime +WORKDIR /app + +# COPY .output folder +COPY --from=build /app/.output ./ + +ENV PORT=3000 +ENV NITRO_PRESET=node-server +ENV HOST=0.0.0.0 + +EXPOSE 3000 + +CMD ["node", "/app/server/index.mjs"]