-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
68 lines (51 loc) · 2.07 KB
/
Dockerfile
File metadata and controls
68 lines (51 loc) · 2.07 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
# ============================================================
# Stage 1: 构建前端 (Node.js)
# ============================================================
FROM node:20-alpine AS frontend-build
WORKDIR /frontend
# 先复制 package.json 利用 Docker 缓存
COPY JuggleNet6.Frontend/package*.json ./
RUN npm ci --prefer-offline
# 复制源码并构建
COPY JuggleNet6.Frontend/ ./
RUN npm run build
# ============================================================
# Stage 2: 构建后端 (.NET 8 SDK)
# ============================================================
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS backend-build
WORKDIR /src
# 先复制 sln 和 csproj,利用 Docker 缓存 restore
COPY Juggle.sln ./
COPY Juggle.Domain/Juggle.Domain.csproj Juggle.Domain/
COPY Juggle.Infrastructure/Juggle.Infrastructure.csproj Juggle.Infrastructure/
COPY Juggle.Application/Juggle.Application.csproj Juggle.Application/
COPY Juggle.Api/Juggle.Api.csproj Juggle.Api/
RUN dotnet restore Juggle.Api/Juggle.Api.csproj
# 复制所有源码
COPY Juggle.Domain/ Juggle.Domain/
COPY Juggle.Infrastructure/ Juggle.Infrastructure/
COPY Juggle.Application/ Juggle.Application/
COPY Juggle.Api/ Juggle.Api/
# 将前端构建产物放入 wwwroot(在 publish 之前)
COPY --from=frontend-build /frontend/dist/ Juggle.Api/wwwroot/
# 发布
RUN dotnet publish Juggle.Api/Juggle.Api.csproj \
-c Release \
-o /app/publish \
--no-restore
# ============================================================
# Stage 3: 最终运行镜像 (.NET 8 Runtime)
# ============================================================
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
WORKDIR /app
# 复制发布产物
COPY --from=backend-build /app/publish .
# 数据目录(SQLite 文件存放在此,通过 volume 持久化)
RUN mkdir -p /data
# 环境变量
ENV ASPNETCORE_ENVIRONMENT=Production
ENV ASPNETCORE_URLS=http://+:9127
# SQLite 数据库路径指向 /data 目录(可通过 -e 覆盖)
ENV DB_PATH=/data/juggle.db
EXPOSE 9127
ENTRYPOINT ["dotnet", "Juggle.Api.dll"]