- Dockerfile:多阶段构建,node:20-alpine 编译 Vue3, nginx:alpine 提供静态资源服务,使用国内 npm 镜像加速 - nginx.conf:配置 Vue Router history 模式(try_files), /api/ 和 /uploads/ 反向代理到后端容器 - .env.production:生产环境 API 地址(8.148.151.56:3001) - .gitignore:放开 .env.production 提交权限(无敏感信息)
15 lines
363 B
Docker
15 lines
363 B
Docker
# 阶段一:编译
|
||
FROM node:20-alpine AS builder
|
||
WORKDIR /app
|
||
COPY package*.json ./
|
||
RUN npm install --registry=https://registry.npmmirror.com
|
||
COPY . .
|
||
RUN npx vite build
|
||
|
||
# 阶段二:Nginx 服务
|
||
FROM nginx:alpine
|
||
COPY --from=builder /app/dist /usr/share/nginx/html
|
||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||
EXPOSE 80
|
||
CMD ["nginx", "-g", "daemon off;"]
|