[英].NetCore microservice CI pipeline Azure DevOps Build error @ docker image
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:我对 docker 技术非常陌生,在 Docker 映像任务的 Azure DevOps CI 管道上创建 .Net Core 3.1 时遇到构建错误:
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.
步骤 7/17 : COPY ["API2/API2.csproj", "API2/"] COPY failed: CreateFile \\?\\C:\\ProgramData\\docker\\tmp\\docker-builder021493529\\API2\\API2.csproj: 系统找不到指定的路径。
My default docker file is我的默认 docker 文件是
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.请让我知道我在哪里做错了。
Here are the docker tasks:以下是 docker 任务:
Here are the folder and files structure on azure DevOps as well:以下是 azure DevOps 上的文件夹和文件结构:
COPY ["API1/API1.csproj", "API1/"]
复制 ["API1/API1.csproj", "API1/"]
Based on the error message, this should the line that caused the error message.根据错误消息,这应该是导致错误消息的行。
Step1:第1步:
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.请确保您没有配置
.dockerignore
文件来排除此文件: API1/API1.csproj
,它必须存在于您运行构建的目录中。
Step2:第2步:
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.上面确认后,现在我们可以根据上下文和您提供的路径来考虑错误是由于服务器无法正确找到
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?根据您的原始定义:
API1/API1.csproj
,我猜您存储库中API1.csproj
的实际路径应该是src/API1/API1.csproj
,对吗?
If yes, here has 2 method you can try:如果是,这里有两种方法您可以尝试:
1). 1)。 Change the
COPY
definition as:将
COPY
定义更改为:
COPY ["API1.csproj", "API1/"]
Updated:更新:
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,但因
Program does not contain a static 'Main' method suitable for an entry point *****
而失败。
Here it means that the COPY . .
这里的意思是
COPY . .
COPY . .
does not copy the files correctly.不能正确复制文件。
At this time, please also change the COPY . .
这时候,也请更改
COPY . .
COPY . .
to COPY . API1/
COPY . API1/
COPY . API1/
. COPY . API1/
。 This will add folder to dest path .这会将文件夹添加到 dest path 。
2). 2)。 Another way is you could specify
API1
to Build context
in task:另一种方法是您可以在任务中指定
API1
来Build context
:
Below is what I am using, and I do not need make any changes into my dockerfile
:以下是我正在使用的内容,我不需要对我的
dockerfile
进行任何更改:
you can input $(Build.Repository.LocalPath)
by replacing hard code the context:您可以通过替换硬编码上下文来输入
$(Build.Repository.LocalPath)
:
Updated:更新:
In Docker 2.*, you can also leave Build context to **
:在 Docker 2.* 中,您还可以将Build 上下文留给
**
:
You can refer to my previous answer on such question: #1 .您可以参考我之前对此类问题的回答: #1 。
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.根据我的意见,我不推荐我上面提到的第一种方法,因为它让你的
dockerfile
与你可以在 Visual Studio 中成功运行的不同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.