nex_docus/frontend/Dockerfile

36 lines
834 B
Docker
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# 构建阶段
FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/node:20-alpine AS builder
# 设置工作目录
WORKDIR /app
# 设置 npm 使用淘宝镜像
RUN npm config set registry https://registry.npmmirror.com
# 复制 package 文件
COPY package.json yarn.lock* package-lock.json* ./
# 清理并安装依赖(解决 Alpine Linux 下 rollup 的 optional dependencies bug
RUN rm -rf package-lock.json node_modules && npm install
# 复制项目文件
COPY . .
# 构建生产版本
RUN npm run build
# 生产阶段
FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nginx:alpine
# 复制构建产物到 nginx
COPY --from=builder /app/dist /usr/share/nginx/html
# 复制 nginx 配置
COPY nginx.conf /etc/nginx/conf.d/default.conf
# 暴露端口
EXPOSE 80
# 启动 nginx
CMD ["nginx", "-g", "daemon off;"]