项目初始化
This commit is contained in:
33
frontend/Dockerfile
Normal file
33
frontend/Dockerfile
Normal file
@@ -0,0 +1,33 @@
|
||||
# 多阶段构建:构建阶段
|
||||
FROM node:18-alpine AS build-stage
|
||||
WORKDIR /app
|
||||
|
||||
# 设置国内镜像源以加速依赖安装(可选,根据实际情况调整)
|
||||
# RUN npm config set registry https://registry.npmmirror.com
|
||||
|
||||
# 复制package.json和package-lock.json
|
||||
COPY package*.json ./
|
||||
|
||||
# 安装依赖
|
||||
RUN npm ci
|
||||
|
||||
# 复制源代码
|
||||
COPY . .
|
||||
|
||||
# 构建应用
|
||||
RUN npm run build
|
||||
|
||||
# 多阶段构建:运行阶段
|
||||
FROM nginx:1.23-alpine AS production-stage
|
||||
|
||||
# 复制构建结果到Nginx
|
||||
COPY --from=build-stage /app/dist /usr/share/nginx/html
|
||||
|
||||
# 复制Nginx配置文件
|
||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||
|
||||
# 暴露端口
|
||||
EXPOSE 80
|
||||
|
||||
# 启动Nginx
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
Reference in New Issue
Block a user