Files
rtsp-video-analysis-system/rtsp-vue/Dockerfile
2025-09-30 20:56:55 +08:00

41 lines
924 B
Docker
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 构建阶段
FROM node:18-alpine AS builder
# 设置工作目录
WORKDIR /app
# 设置npm镜像源
RUN npm config set registry https://registry.npmmirror.com
# 复制package.json和package-lock.json
COPY package*.json ./
# 安装依赖
RUN npm install
# 复制源代码
COPY . .
# 构建生产环境项目
RUN npm run build:prod
# 运行阶段
FROM nginx:1.25-alpine
# 安装curl和envsubst用于健康检查和环境变量替换
RUN apk add --no-cache curl gettext
# 删除默认nginx配置
RUN rm -rf /etc/nginx/conf.d/*
# 复制nginx配置
COPY nginx.conf /etc/nginx/conf.d/default.conf
# 复制构建产物
COPY --from=builder /app/dist /usr/share/nginx/html
# 暴露端口
EXPOSE 80
# 使用envsubst替换环境变量然后启动Nginx
CMD sh -c "envsubst '\$NGINX_PORT' < /etc/nginx/conf.d/default.conf > /tmp/nginx.conf && mv /tmp/nginx.conf /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"