From ca2c0d69a2701a218a83701b7c77cea9e6916166 Mon Sep 17 00:00:00 2001 From: movingsam Date: Fri, 27 Feb 2026 22:06:29 +0800 Subject: [PATCH] =?UTF-8?q?fix(dockerfile):=20=E4=BF=AE=E6=AD=A3Docker?= =?UTF-8?q?=E6=9E=84=E5=BB=BA=E6=B5=81=E7=A8=8B=E5=92=8C=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删除多余的目录拷贝,简化COPY指令 - 统一项目文件和配置文件的拷贝路径 - 调整工作目录,避免重复嵌套路径 - 优化dotnet restore和build步骤,确保路径正确 - 保持publish阶段项目路径一致,确保发布成功 --- Dockerfile | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3442a56..dfa6b81 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,21 +7,24 @@ EXPOSE 8081 FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build ARG BUILD_CONFIGURATION=Release WORKDIR /src -# Copy Directory.Packages.props for centralized version management + +# Copy project files COPY ["Directory.Packages.props", "./"] -COPY ["src/Directory.Packages.props", "src/"] -COPY ["src/YarpGateway/YarpGateway.csproj", "src/YarpGateway/"] -COPY ["src/Fengling.ServiceDiscovery/Fengling.ServiceDiscovery.Core/Fengling.ServiceDiscovery.Core.csproj", "src/Fengling.ServiceDiscovery/Fengling.ServiceDiscovery.Core/"] -COPY ["src/Fengling.ServiceDiscovery/Fengling.ServiceDiscovery.Kubernetes/Fengling.ServiceDiscovery.Kubernetes.csproj", "src/Fengling.ServiceDiscovery/Fengling.ServiceDiscovery.Kubernetes/"] -COPY ["src/Fengling.ServiceDiscovery/Fengling.ServiceDiscovery.Static/Fengling.ServiceDiscovery.Static.csproj", "src/Fengling.ServiceDiscovery/Fengling.ServiceDiscovery.Static/"] -RUN dotnet restore "src/YarpGateway/YarpGateway.csproj" +COPY ["YarpGateway.csproj", "./"] +COPY ["NuGet.Config", "./"] + +# Restore dependencies +RUN dotnet restore "YarpGateway.csproj" + +# Copy all source code COPY . . -WORKDIR "/src/src/YarpGateway" -RUN dotnet build "./YarpGateway.csproj" -c $BUILD_CONFIGURATION -o /app/build + +WORKDIR "/src" +RUN dotnet build "YarpGateway.csproj" -c $BUILD_CONFIGURATION -o /app/build FROM build AS publish ARG BUILD_CONFIGURATION=Release -RUN dotnet publish "./YarpGateway.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false +RUN dotnet publish "YarpGateway.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false FROM base AS final WORKDIR /app