.NetCore微服务CI管道Azure DevOps构建错误@ docker image [英] .NetCore microservice CI pipeline Azure DevOps Build error @ docker image

查看:92
本文介绍了.NetCore微服务CI管道Azure DevOps构建错误@ docker image的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Docker技术上非常新,在Docker映像任务上的Azure DevOps CI管道上创建.Net Core 3.1时遇到构建错误:

I am very much new on docker technology, I am getting the build error while creating the .Net Core 3.1 on Azure DevOps CI pipeline on Docker image tasks:

步骤7/17:COPY ["API2/API2.csproj","API2/"] COPY失败:CreateFile \?\ C:\ ProgramData \ docker \ tmp \ docker-builder021493529 \ API2 \ API2.csproj: 系统找不到指定的路径.

Step 7/17 : COPY ["API2/API2.csproj", "API2/"] COPY failed: CreateFile \?\C:\ProgramData\docker\tmp\docker-builder021493529\API2\API2.csproj: The system cannot find the path specified.

我的默认docker文件是

My default docker file is

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1809 AS base 
WORKDIR /app 
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-nanoserver-1809 AS build
WORKDIR /src
COPY ["API1/API1.csproj", "API1/"]
RUN dotnet restore "API1/API1.csproj"
COPY . .
WORKDIR "/src/API1"
RUN dotnet build "API1.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "API1.csproj" -c Release -o /app/publish
FROM base AS final 
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "API1.dll"] 

请务必从我做错的地方告诉我.

Please do let me know from where I am doing mistake.

以下是docker任务:

Here are the docker tasks:

这也是azure DevOps上的文件夹和文件结构:

Here are the folder and files structure on azure DevOps as well:

推荐答案

COPY ["API1/API1.csproj","API1/"]

COPY ["API1/API1.csproj", "API1/"]

根据错误消息,这应该是导致错误消息的行.

Based on the error message, this should the line that caused the error message.

第一步:

请确保未配置.dockerignore文件以排除该文件:API1/API1.csproj,该文件必须存在于运行生成文件的目录中.

Please ensure you did not configure the .dockerignore file to exclude this file: API1/API1.csproj, which must exists in the directory where you run your build from.

第二步:

经过上面的确认,现在我们可以通过遵循您提供的上下文和路径来考虑错误是由于服务器无法正确找到csproj文件引起的.

After above confirmed, now we can consider the error is caused about the server could not find the csproj file correctly by following the context and the path you provided.

根据您的原始定义:API1/API1.csproj,我想存储库中API1.csproj的实际路径应该为src/API1/API1.csproj,对吧?

According to the your original definition: API1/API1.csproj, I guess the actual path of API1.csproj in your repository should be src/API1/API1.csproj, right?

如果是,您可以尝试以下两种方法:

If yes, here has 2 method you can try:

1).COPY定义更改为:

    COPY ["API1.csproj", "API1/"]

已更新:

Updated:

应用此方法时,可能会成功进行COPY操作,但会失败,并显示Program does not contain a static 'Main' method suitable for an entry point *****.

When you apply this method, you may succeed to COPY, but failed with Program does not contain a static 'Main' method suitable for an entry point *****.

这表示COPY . .无法正确复制文件.

Here it means that the COPY . . does not copy the files correctly.

这时,请同时将COPY . .更改为COPY . API1/.这将将文件夹添加到目标路径.

At this time, please also change the COPY . . to COPY . API1/. This will add folder to dest path.

2).另一种方法是,您可以在任务中将API1设置为Build context:

2). Another way is you could specify API1 to Build context in task:

下面是我正在使用的,我不需要对我的dockerfile进行任何更改:

Below is what I am using, and I do not need make any changes into my dockerfile:

您可以通过替换上下文的硬代码来输入$(Build.Repository.LocalPath):

you can input $(Build.Repository.LocalPath) by replacing hard code the context:

已更新:

Updated:

在Docker 2. *中,您还可以将 Build context (构建上下文)留给**:

In Docker 2.*, you can also leave Build context to **:

您可以参考我以前对以下问题的回答:#1 .

You can refer to my previous answer on such question: #1.

根据我的意见,我不建议您使用上面提到的第一种方法,因为它使您的dockerfile与可以在Visual Studio中成功运行的方法有所不同.

Based on my opinions, I am not recommend the first method I mentioned above, because it let your dockerfile different with the one which you can run successfully in Visual studio.

这篇关于.NetCore微服务CI管道Azure DevOps构建错误@ docker image的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆