61 lines
1.6 KiB
Docker
61 lines
1.6 KiB
Docker
# 基于 .NET 8 运行时镜像
|
|
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
|
|
WORKDIR /app
|
|
EXPOSE 9996
|
|
|
|
# 设置时区
|
|
ENV TZ=Asia/Shanghai
|
|
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
|
|
|
# 安装字体和依赖
|
|
RUN apt-get update && apt-get install -y \
|
|
fonts-liberation \
|
|
fonts-dejavu-core \
|
|
fonts-wqy-zenhei \
|
|
fontconfig \
|
|
&& apt-get clean \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# 重建字体缓存
|
|
RUN fc-cache -fv
|
|
|
|
# 构建阶段
|
|
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
|
ARG BUILD_CONFIGURATION=Release
|
|
WORKDIR /src
|
|
|
|
# 先拷贝 csproj 文件,利用 Docker 缓存
|
|
COPY ["YD_Event.Web.Entry/YD_Event.Web.Entry.csproj", "YD_Event.Web.Entry/"]
|
|
COPY ["YD_Event.Web.Core/YD_Event.Web.Core.csproj", "YD_Event.Web.Core/"]
|
|
COPY ["YD_Event.Application/YD_Event.Application.csproj", "YD_Event.Application/"]
|
|
COPY ["YD_Event.Core/YD_Event.Core.csproj", "YD_Event.Core/"]
|
|
|
|
# 恢复依赖
|
|
RUN dotnet restore "YD_Event.Web.Entry/YD_Event.Web.Entry.csproj"
|
|
|
|
# 拷贝全部源代码
|
|
COPY . .
|
|
|
|
WORKDIR "/src/YD_Event.Web.Entry"
|
|
|
|
# 构建
|
|
RUN dotnet build "YD_Event.Web.Entry.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
|
|
|
# 发布
|
|
FROM build AS publish
|
|
ARG BUILD_CONFIGURATION=Release
|
|
RUN dotnet publish "YD_Event.Web.Entry.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
|
|
|
|
# 运行镜像
|
|
FROM base AS final
|
|
WORKDIR /app
|
|
COPY --from=publish /app/publish .
|
|
|
|
# 配置 Kestrel 端口
|
|
ENV ASPNETCORE_URLS=http://*:9996
|
|
|
|
# 健康检查
|
|
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
|
|
CMD curl -f http://localhost:9996/health || exit 1
|
|
|
|
ENTRYPOINT ["dotnet", "YD_Event.Web.Entry.dll"] |