[英]How to build one docker image for multiple projects?
在我的項目中,我使用 .net core 2.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 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
錯誤消息非常簡單,您在構建它的JenkinsService.csproj
容器中缺少該項目中的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"]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.