YD_Event.Admin/Dockerfile
2026-02-23 18:32:49 +08:00

49 lines
1.5 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 基于.NET 8官方Linux镜像的多阶段构建
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
# 安装必要的依赖(如字体库,适配MiniExcel等)
RUN apt-get update && apt-get install -y fontconfig && apt-get clean
# 构建阶段
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
# 复制csproj文件并还原
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"]