我想在PowerShell中创建脚本来构建和复制项目,以便dockerfile可以运行应用程序。
就目前而言,dockerfile还原NuGet软件包,编译项目,然后运行应用程序。对于这些操作,它取决于映像microsoft / dotnet:2.2-sdk,但是太大。因此,我需要重写dockerfile,以便它仅接收已编译的项目并运行应用程序。
这是我的dockerfile的样子:
FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM microsoft/dotnet:2.2-sdk AS build
WORKDIR .
COPY ["Project.Api/Project.Api.csproj", "Project.Api/"]
COPY ["Project.Context/Project.Context.csproj", "Project.Context/"]
COPY ["Context.Common/Context.Common.csproj", "Context.Common/"]
COPY ["Project.InternalData/Project.InternalData.csproj", "Project.InternalData/"]
COPY ["Project.ProjectData/Project.ProjectData.csproj", "Project.ProjectData/"]
COPY ["Hateoas/Hateoas.csproj", "Hateoas/"]
RUN dotnet restore "Project.Api/Project.Api.csproj"
COPY . .
WORKDIR "Project.Api"
RUN dotnet build "Project.Api.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "Project.Api.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Project.Api.dll"]