本文介绍了在 Visual Studio 中使用相同的 docker 文件构建 docker 映像的 Azure Pipeline 失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个部署管道来将我的映像部署到 Kubernetes 集群.此过程的第一步是基于 docker 文件创建映像.我正在使用的 docker 文件是在我添加 docker 支持时从 Visual Studio 生成的,并在右键单击 docker 图像并选择创建它时成功创建了图像.当我配置 Azure Pipeline 时,创建 docker 映像会在尝试构建实际解决方案时失败.上一步获取了所有源文件,但在使用

I'm trying to create a deployment pipeline to deploy my image to Kubernetes cluster. The first step in this process is to create an image based on the docker file. The docker file I'm using was generated from Visual Studio when I added docker support and successfully creates the image when right clicking on the docker image and selecting to create it. When I configure the Azure Pipeline, the create docker image fails as soon as it tries to build the actual solution. The previous step grabs all the sources files but then fails on the docker image creation with

[error]COPY failed: stat/var/lib/docker/tmp/docker-builder158012929/DockerTest/DockerTest.csproj:
 no such file or directory

[error]/usr/bin/docker failed with return code: 1

以下是 Visual Studio 生成的 docker 文件,由 azure 管道阶段引用以创建 docker 镜像.

The following is the docker file generated from Visual studio and is referenced by the azure pipeline stage to create the docker image.

 FROM mcr.microsoft.com/dotnet/core/runtime:2.2-stretch-slim AS base

 WORKDIR /app
 FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS
 build

 WORKDIR /src
 COPY ["DockerTest/DockerTest.csproj", "DockerTest/"]
 RUN dotnet restore "DockerTest/DockerTest.csproj"
 COPY . .
 WORKDIR "/src/DockerTest"
 RUN dotnet build "DockerTest.csproj" -c Release -o /app

 FROM build AS publish
 RUN dotnet publish "DockerTest.csproj" -c Release -o /app

 FROM base AS final
 WORKDIR /app
 COPY --from=publish /app .
 ENTRYPOINT ["dotnet", "DockerTest.dll"]

##[section]开始:构建容器镜像
============================================================================ 任务:Docker 描述:构建、标记、推送或运行 Docker 镜像,或运行 Docker 命令.任务可以与 Docker 或 Azure 容器一起使用注册表.版本:0.150.6 作者:微软公司 帮助:[更多信息]https://go.microsoft.com/fwlink/?linkid=848006)
============================================================================== [命令]/usr/bin/docker build -f
/home/vsts/work/1/s/DockerTest/Dockerfile -tihacontainers.azurecr.io/dockertest:6/home/vsts/work/1/s/DockerTest将构建上下文发送到 Docker 守护进程 6.144kB 步骤 1/15:FROMmcr.microsoft.com/dotnet/core/runtime:2.2-stretch-slim AS base2.2-stretch-slim:从 dotnet/core/runtime 拉取 743f2d6c1f65:拉取 fs 层 074da88b8de0:拉取 fs 层 ac831735b47a:拉取fs 层 3adcc844418d:拉动 fs 层 3adcc844418d:等待ac831735b47a:下载完整的 743f2d6c1f65:验证校验和743f2d6c1f65:下载完成 074da88b8de0:验证校验和074da88b8de0:下载完整的 3adcc844418d:验证校验和zadcc844418d:下载完成 743f2d6c1f65:拉取完成074da88b8de0:拉完整 ac831735b47a:拉完整 3adcc844418d:拉完整摘要:sha256:066c31b113b0a20e6155d3bd8a314563c688d2ec31c11d7e551af5bc2595f30c状态:已下载更新的图像mcr.microsoft.com/dotnet/core/runtime:2.2-stretch-slim --->c0f9ab44ecc1 第 2/15 步:WORKDIR/app ---> 在 6d1a5f5600dd 中运行移除中间容器 6d1a5f5600dd ---> 527fcebeaf1f Step3/15:来自 mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build2.2-stretch:从 dotnet/core/sdk 拉取 c5e155d5a1d1:拉取 fs 层 221d80d00ae9:拉取 fs 层 4250b3117dca:拉取 fs 层3b7ca19181b2:拉 fs 层 3466298fc231:拉 fs 层310737d73ed1:拉 fs 层 dc981de74fae:拉 fs 层3b7ca19181b2:等待 3466298fc231:等待 310737d73ed1:等待dc981de74fae:等待 4250b3117dca:验证校验和 4250b3117dca:下载完整的 221d80d00ae9:验证校验和 221d80d00ae9:下载完整 3466298fc231:验证校验和 3466298fc231:下载完整的 c5e155d5a1d1:验证校验和 c5e155d5a1d1:下载完整的 3b7ca19181b2:验证校验和 3b7ca19181b2:下载完整 c5e155d5a1d1:拉完整 221d80d00ae9:拉完成 310737d73ed1:验证校验和 310737d73ed1:下载完整 4250b3117dca:拉完整 dc981de74fae:验证校验和dc981de74fae:下载完成 3b7ca19181b2:拉取完成3466298fc231:拉完整 310737d73ed1:拉完整 dc981de74fae:拉完整摘要:sha256:222cc0bb0bc93875ee0f6be626b2838beea838f65e53653e07c33eb9d00b0163状态:已下载更新的图像mcr.microsoft.com/dotnet/core/sdk:2.2-stretch ---> e4747ec2aaff 步骤4/15 : WORKDIR/src ---> 在 a7ebcac87f68 中运行正在删除中间容器 a7ebcac87f68 ---> d7541674a9da 第 5/15 步:复制 ["DockerTest/DockerTest.csproj", "DockerTest/"] 复制失败:统计/var/lib/docker/tmp/docker-builder158012929/DockerTest/DockerTest.csproj:no这样的文件或目录

##[error]COPY 失败:stat/var/lib/docker/tmp/docker-builder158012929/DockerTest/DockerTest.csproj:no此类文件或目录

##[error]/usr/bin/docker failed with return code: 1 ##[section]Finishing: Build a container image

推荐答案

根据这个错误信息,错误发生在你的dockerfile的那一行:COPY ["DockerTest/DockerTest.csproj", "DockerTest/"].

According to this error message, the error occurred on the line of your dockerfile: COPY ["DockerTest/DockerTest.csproj", "DockerTest/"].

首先,请确认您没有使用 .dockerignore 文件来排除此文件:DockerTest/DockerTest.csproj,它必须存在于您运行您的目录中构建自.

First, please confirm that you did not use .dockerignore file to exclude this file: DockerTest/DockerTest.csproj, which must exists in the directory where you run your build from.

如果它没有被 .dockerignore 文件忽略,那么你需要考虑你的 dockerfile 位置级别.

If it does not ignored by .dockerignore file, then you need to consider about your dockerfile location level.

DockerTest.csproj 文件不应放在较低的源文件路径级别.您需要更改上下文的来源,将其移动到更高级别.因此,手动修改您的 dockerfile 为:

DockerTest.csproj file should not put at the lower source file path level. You need to change the source of the context, move it at a higher level. So modify your dockerfile manually as :

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

这篇关于在 Visual Studio 中使用相同的 docker 文件构建 docker 映像的 Azure Pipeline 失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

查看更多