简体   繁体   English

如何为多个项目构建一个 docker 镜像?

[英]How to build one docker image for multiple projects?

In my project I am using .net core 2.2 , recently I am using additional class library inside my project.在我的项目中,我使用 .net core 2.2 ,最近我在我的项目中使用了额外的类库。 When I am trying to build my image it can not found my dll.当我尝试构建我的映像时,它找不到我的 dll。

My docker file looks like:我的 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"]

I am getting error like this:我收到这样的错误:

 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

The error message is pretty straightforward, you're missing JenkinsService.csproj and other files from this project in docker container where you build it.错误消息非常简单,您在构建它的JenkinsService.csproj容器中缺少该项目中的JenkinsService.csproj和其他文件。 You need to copy these files as well.您还需要复制这些文件。

If you're using Visual Studio the easiest way to do it is to right-click executable project file ( LibvirtManagement in your case) and then select Add -> Docker Support... .如果您使用的是 Visual Studio,最简单的方法是右键单击可执行项目文件(在您的情况下为LibvirtManagement ),然后选择Add -> Docker Support... It will auto-generate correct Dockerfile for you它将为您自动生成正确的Dockerfile

EDIT: this is what this tool created for me:编辑:这是这个工具为我创建的:

#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.

相关问题 从具有多个项目的解决方案构建 docker 容器 - Build docker container from solution with multiple projects 如何为.NET解决方案构建具有多个依赖项的Docker映像? - How to build a Docker image with multiple dependencies for .NET Solution? 如何将多个项目复制到单个 Docker 容器中 - How to copy multiple projects into a single Docker container 如何在一个文件夹中构建所有项目? - How to build all projects in one single folder? 如何在Visual Studio中构建和运行多个项目 - How to build and run multiple projects in Visual Studio 如何使多个.net项目仅在构建中一次复制引用 - How to make multiple .net projects copy references only one time in the build 如何从解决方案中的一个项目运行程序作为构建步骤? - How to run a program from one of the projects in a solution as a build step? 在 Visual Studio Online Build Definition 中从具有多个 Web 项目的解决方案构建一个 Web 项目 - Build one web project from a Solution with multiple web projects in Visual Studio Online Build Definition 如何构建和部署具有多个项目的Visual Studio解决方案 - How to build and deploy a visual studio solution with multiple projects 如何使用要在多个其他 MVC 项目中使用的表单构建项目 - How to build a project with forms to be used in multiple other MVC projects
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM