blob: e3823879fe7d4e6f76953e96418159562ee6b434 [file] [log] [blame]
223010806af19da2025-06-03 16:57:13 +08001# 使用官方 Ubuntu 基础镜像
2FROM ubuntu:22.04
3
4# 安装 Node.js 和 npm
5RUN apt-get update && \
6 apt-get install -y curl gnupg && \
7 curl -sL https://deb.nodesource.com/setup_20.x | bash - && \
8 apt-get install -y nodejs
9
10# 安装 Nginx
11RUN apt-get install -y nginx && \
12 apt-get clean && \
13 rm -rf /var/lib/apt/lists/*
14
15# 设置工作目录
16WORKDIR /app
17
18# 复制应用程序文件
19COPY . .
20
21# 安装应用程序依赖
22RUN npm install
23
24# 构建应用程序
25RUN npm run build
26
27# 将构建好的 React 应用复制到 Nginx 的目录下
28RUN cp -r build/* /var/www/html/
29
30# 复制 Nginx 配置文件到容器
31COPY ./nginx.conf /etc/nginx/sites-available/default
32
33# 映射出来的 Nginx 配置目录
34VOLUME /etc/nginx/sites-enabled
35
36# 暴露 80 端口
37EXPOSE 80
38
39# 启动 Nginx 服务器
40CMD ["nginx", "-g", "daemon off;"]