简体   繁体   English

.NetCore 微服务 CI 管道 Azure DevOps 构建错误 @ docker image

[英].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:另一种方法是您可以在任务中指定API1Build 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.

相关问题 docker 任务上的 .NetCore CI 管道错误 - .NetCore CI pipeline error on docker tasks Azure Devops 管道 Docker 构建 - Azure Devops Pipeline Docker Build Docker 映像构建在 Azure DevOps 发布管道中失败 - Docker image build fails in Azure DevOps release pipeline 在 Azure DevOps 管道中使用 docker/buildx 构建多体系结构映像 - Build multi architecture image using docker/buildx in Azure DevOps pipeline 发布管道 Azure DevOps 中的 Docker 映像失败,错误代码为 145 - Docker image in Release Pipeline Azure DevOps Failed with error code 145 Azure DevOps Pipeline 中 Docker 映像中的单元测试 - Unit testing in Docker image in Azure DevOps Pipeline Azure DevOps 管道 - 构建并推送 Docker 图像到 Azure 容器注册表,具有 restricted.network 访问权限 - Azure DevOps Pipeline - build and push Docker Image to Azure container registry with restricted network access 尝试在 azure devops CICD 中构建映像时出现 docker 错误 - docker error while trying to build an image in azure devops CICD 将 docker 镜像从 Azure DevOps 管道推送到 Docker Hub - Pushing docker image to Docker Hub from Azure DevOps pipeline 环境变量未注入 Azure Devops 管道上的多阶段 docker 构建 - Environment variable not injected into multi stage docker build on Azure Devops pipeline
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM