C# 如何为多个项目构建一个docker映像?
在我的项目中,我使用.NETCore2.2,最近我在项目中使用了额外的类库。 当我试图建立我的形象,它无法找到我的dll 我的docker文件如下所示:C# 如何为多个项目构建一个docker映像?,c#,docker,asp.net-core,C#,Docker,Asp.net Core,在我的项目中,我使用.NETCore2.2,最近我在项目中使用了额外的类库。 当我试图建立我的形象,它无法找到我的dll 我的docker文件如下所示: FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build-env WORKDIR /app # Copy csproj and restore as distinct layers COPY *.csproj ./ RUN dotnet restore COPY . ./ RUN dotnet p
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
COPY . ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2
WORKDIR /app
EXPOSE 80
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "LibvirtManagement.dll"]
我得到的错误如下:
The project file "/JenkinsService/JenkinsService.csproj" was not found.
[/app/LibvirtManagement.sln]
The command '/bin/sh -c dotnet publish -c Release -o out' returned a non-zero code: 1
错误消息非常简单,您在构建该项目的docker容器中缺少了该项目的
JenkinsService.csproj
和其他文件。您还需要复制这些文件
如果您使用的是Visual Studio,最简单的方法是右键单击可执行项目文件(LibvirtManagement
),然后选择Add->Docker Support…
。它将自动为您生成正确的Dockerfile
编辑:这是该工具为我创建的内容:
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build
WORKDIR /src
COPY ["LibvirtManagement/LibvirtManagement.csproj", "LibvirtManagement/"]
COPY ["JenkinsService/JenkinsService.csproj", "JenkinsService/"]
RUN dotnet restore "LibvirtManagement/LibvirtManagement.csproj"
COPY . .
WORKDIR "/src/LibvirtManagement"
RUN dotnet build "LibvirtManagement.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "LibvirtManagement.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "LibvirtManagement.dll"]
我得到了这个错误
COPY[“LibvirtManagement/LibvirtManagement.csproj”,“LibvirtManagement/”]复制失败:stat/var/lib/docker/tmp/docker-builder036005313/LibvirtManagement/LibvirtManagement.csproj:在我的项目中没有这样的文件或目录,在我的情况下,我不知道这是否有意义。因为我不想在这里发布代码