增加官网的dockerfile

This commit is contained in:
dxin
2025-11-27 15:17:39 +08:00
parent 3619948529
commit 16fcc5dc72
4 changed files with 298 additions and 11 deletions

View File

@@ -0,0 +1,78 @@
FROM node:20-bullseye AS builder
WORKDIR /app
# 安装编译工具和 SQLite
RUN apt-get update && \
apt-get install -y --no-install-recommends \
python3 \
make \
g++ \
gcc \
sqlite3 \
libsqlite3-dev && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# 环境变量设置
ENV NUXT_TELEMETRY_DISABLED=1
# 复制所有源代码
COPY ./projects/lessie ./
# 删除可能从主机复制过来的 node_modules
RUN rm -rf node_modules
RUN rm -rf .pnpm-store
RUN rm -rf package-lock.json
# 安装 pnpm v9 (v10 有严格的构建脚本安全限制)
RUN npm install -g pnpm@9
# 重新安装所有依赖(在容器内从零开始编译)
RUN pnpm install --no-frozen-lockfile
# 再次尝试 rebuild better-sqlite3 以确保编译成功
RUN pnpm rebuild better-sqlite3
# 设置生产环境变量
ENV NODE_ENV=production
ENV HOST=0.0.0.0
ENV PORT=3000
# 构建 Nuxt 应用
RUN pnpm run build
RUN ls -a
FROM node:20-slim AS runtime
# 安装 nginx
RUN apt-get update && \
apt-get install -y --no-install-recommends nginx && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# 拷贝你的 nginx 配置
COPY nginx.conf /etc/nginx/nginx.conf
COPY --from=builder /app/.output /app
EXPOSE 80
WORKDIR /app
# 创建启动脚本nginx 在后台启动node 在前台运行
RUN echo '#!/bin/sh' > /start.sh && \
echo 'echo "启动 Nginx..."' >> /start.sh && \
echo 'nginx' >> /start.sh && \
echo 'echo "Nginx 已启动"' >> /start.sh && \
echo 'echo "启动 Node.js 应用..."' >> /start.sh && \
echo 'exec node /app/server/index.mjs' >> /start.sh && \
chmod +x /start.sh
# 启动脚本nginx 后台运行node 前台运行
CMD ["/start.sh"]