# 使用 .NET 8 SDK 作为构建镜像 FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build WORKDIR /src # 复制解决方案文件和项目文件 COPY ["AssetManager.sln", "."] COPY ["AssetManager.API/AssetManager.API.csproj", "AssetManager.API/"] COPY ["AssetManager.Services/AssetManager.Services.csproj", "AssetManager.Services/"] COPY ["AssetManager.Infrastructure/AssetManager.Infrastructure.csproj", "AssetManager.Infrastructure/"] COPY ["AssetManager.Models/AssetManager.Models.csproj", "AssetManager.Models/"] COPY ["AssetManager.Data/AssetManager.Data.csproj", "AssetManager.Data/"] # 还原 NuGet 包 RUN dotnet restore "AssetManager.API/AssetManager.API.csproj" # 复制所有文件并构建 COPY . . WORKDIR "/src/AssetManager.API" RUN dotnet build "AssetManager.API.csproj" -c Release -o /app/build # 发布应用 FROM build AS publish RUN dotnet publish "AssetManager.API.csproj" -c Release -o /app/publish /p:UseAppHost=false # 构建最终运行时镜像 FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base WORKDIR /app EXPOSE 8080 EXPOSE 8081 # 设置时区为 Asia/Shanghai ENV TZ=Asia/Shanghai RUN apt-get update && apt-get install -y tzdata && ln -sf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone # 从发布阶段复制文件 FROM base AS final WORKDIR /app COPY --from=publish /app/publish . # 配置环境变量(可以在运行时覆盖) ENV ASPNETCORE_ENVIRONMENT=Production ENV ASPNETCORE_URLS=http://+:8080 # 启动应用 ENTRYPOINT ["dotnet", "AssetManager.API.dll"]