简体   繁体   English

.Net 核心 docker 构建与多个项目

[英].Net core docker build with multiple projects

Net core project and I have many webapi, business layer and some other layers here. Net core 项目,我这里有很多 webapi、业务层和其他一些层。 Below is the folder stucture.下面是文件夹结构。

Main Solution主要解决方案

  1. businessLayer业务层
  2. data layer数据层
  3. Web API layer 3.1 MyDockerFile Web API 层 3.1 MyDockerFile

Below is my docker file.下面是我的 docker 文件。

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /app

COPY ["Enrichment.WebApi/Enrichment.WebApi.csproj", "Enrichment.WebApi/"]
COPY ["Enrichment.Facade/Enrichment.Facade.csproj", "Enrichment.Facade/"]
COPY ["Enrichment.Saga/Enrichment.Saga.csproj", "Enrichment.Saga/"]
COPY ["Enrichment.BusinessModel/Enrichment.BusinessModel.csproj", "Enrichment.BusinessModel/"]
RUN dotnet restore "Enrichment.WebApi/Enrichment.WebApi.csproj"

COPY *.csproj ./
RUN dotnet restore

# Copy everything else and build
COPY . ./

RUN dotnet publish -c Release -o out

# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "Enrichment.WebApi.dll"]

When I run docker build -t enrichment.webapi .当我运行 docker build -t richment.webapi 时。 I get below output我得到低于输出

Sending build context to Docker daemon  230.8MB
Step 1/16 : FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
 ---> 9a88f73dec65
Step 2/16 : WORKDIR /app
 ---> Using cache
 ---> 9b50f1fc6721
Step 3/16 : COPY ["Enrichment.WebApi/Enrichment.WebApi.csproj", "Enrichment.WebApi/"]
COPY failed: stat /var/lib/docker/tmp/docker-builder437963979/Enrichment.WebApi/Enrichment.WebApi.csproj: no such file or directory

I am not able to understand why I am getting above error.我无法理解为什么会出现上述错误。 Path looks like incorrect but I am not able to understand what would be the right path.路径看起来不正确,但我无法理解什么是正确的路径。 can someone help me to understand any issue here.有人可以帮我理解这里的任何问题吗? Any help would be appreciated.任何帮助,将不胜感激。 Thank you.谢谢你。

Step 9/16 : COPY *.csproj ./ COPY failed: no source files were specified

This is because of .dockerignore file that ignores the csproj .这是因为.dockerignore文件忽略了csproj Notice the content of .dockerignore below and Anything other than obj/Docker/publish/* and obj/Docker/empty is ignored.请注意下面.dockerignore的内容, .dockerignore obj/Docker/publish/*obj/Docker/empty以外的任何内容。

*
!obj/Docker/publish/*
!obj/Docker/empty/

Incude this in your dockerfile将此包含在您的 dockerfile 中

# build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 
WORKDIR /app
COPY --from=build-env /app/out ./

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM