添加 Dockerfile
This commit is contained in:
35
Dockerfile
Normal file
35
Dockerfile
Normal file
@ -0,0 +1,35 @@
|
||||
# 构建阶段
|
||||
FROM docker.1ms.run/node:16 AS builder
|
||||
|
||||
# 设置工作目录
|
||||
WORKDIR /app
|
||||
|
||||
# 复制 package.json 和 package-lock.json
|
||||
COPY package*.json ./
|
||||
|
||||
# 安装依赖
|
||||
RUN npm ci
|
||||
|
||||
# 复制所有项目文件
|
||||
COPY . .
|
||||
|
||||
# 创建环境变量文件
|
||||
RUN touch .env
|
||||
|
||||
# 构建应用
|
||||
RUN npm run build
|
||||
|
||||
# 生产阶段
|
||||
FROM docker.1ms.run/nginx:stable-alpine
|
||||
RUN rm -rf /usr/share/nginx/html/*
|
||||
# 复制构建后的文件到Nginx服务器
|
||||
COPY --from=builder /app/dist /usr/share/nginx/html
|
||||
|
||||
# 复制自定义Nginx配置(如有需要)
|
||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||
|
||||
# 暴露9800端口
|
||||
EXPOSE 9800
|
||||
|
||||
# 启动Nginx
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
Reference in New Issue
Block a user