35 lines
605 B
Docker
35 lines
605 B
Docker
FROM node:slim-alpine AS build
|
|
|
|
# 创建工作目录
|
|
WORKDIR /app
|
|
|
|
# 安装 pnpm
|
|
RUN npm install -g pnpm
|
|
|
|
# 复制 package.json 和 pnpm-lock.yaml
|
|
COPY package.json pnpm-lock.yaml ./
|
|
|
|
# 安装依赖
|
|
RUN pnpm install
|
|
|
|
# 复制源代码
|
|
COPY . .
|
|
|
|
# 构建前端项目
|
|
RUN pnpm run build
|
|
|
|
# 使用 nginx 作为生产环境的 web 服务器
|
|
FROM nginx:23-alpine
|
|
|
|
# 复制构建好的文件到 nginx 目录
|
|
COPY --from=build /app/dist /usr/share/nginx/html
|
|
|
|
# 复制 nginx 配置文件
|
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
|
|
|
# 暴露端口
|
|
EXPOSE 80
|
|
|
|
# 启动 nginx
|
|
CMD ["nginx", "-g", "daemon off;"]
|