-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDockerfile
More file actions
68 lines (50 loc) · 1.69 KB
/
Copy pathDockerfile
File metadata and controls
68 lines (50 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# 个人网站 - 全栈 Docker 镜像
# 包含前端(React)和后端(Spring Boot)在一个容器中
# ================================
# Stage 1: 构建后端
# ================================
FROM maven:3.9-eclipse-temurin-21-alpine AS backend-builder
WORKDIR /app/backend
# 复制后端 pom.xml
COPY backend/pom.xml ./
# 下载依赖 (利用 Docker 缓存)
RUN mvn dependency:go-offline -B
# 复制后端源码
COPY backend/src ./src
# 构建后端
RUN mvn clean package -DskipTests -B
# ================================
# Stage 2: 生产镜像 (Ubuntu)
# ================================
FROM ubuntu:22.04
LABEL maintainer="Claw"
LABEL description="Personal Website - Full Stack (Frontend + Backend)"
LABEL version="1.0"
# 安装 nginx 和 supervisor
RUN apt-get update && apt-get install -y \
nginx \
supervisor \
openjdk-21-jre-headless \
wget \
&& rm -rf /var/lib/apt/lists/*
# 创建应用目录
WORKDIR /app
# 从构建阶段复制后端 JAR
COPY --from=backend-builder /app/backend/target/*.jar app.jar
# 复制本地预构建的前端产物
COPY frontend/dist /var/www/html
# 复制 nginx 配置 (覆盖默认站点)
COPY docker/nginx.conf /etc/nginx/sites-enabled/default
# 复制 supervisor 配置 (管理多个进程)
COPY docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
# 创建数据目录
RUN mkdir -p /app/data
# 暴露端口
# 80: 前端 (nginx)
# 8080: 后端 API
EXPOSE 80 8080
# 健康检查
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/api/public/profile || exit 1
# 启动 supervisor
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]