dockerfile 提交
This commit is contained in:
parent
83e4fef459
commit
a4de6a041a
27
Dockerfile
27
Dockerfile
@ -1,48 +1,49 @@
|
||||
# 基于.NET 8官方Linux镜像的多阶段构建
|
||||
# 基于 .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
|
||||
|
||||
# 安装必要的依赖(如字体库,适配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文件并还原
|
||||
# 先拷贝 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端口
|
||||
# 配置 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"]
|
||||
ENTRYPOINT ["dotnet", "YD_Event.Web.Entry.dll"]
|
||||
Loading…
x
Reference in New Issue
Block a user