在 Visual Studio 中使用相同的 docker 文件构建 docker 映像的 Azure Pipeline 失败 [英] Azure Pipeline to build docker images fails using same docker file in Visual Studio

查看:10
本文介绍了在 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这样的文件或目录

##[section]Starting: Build a container image
============================================================================== Task: Docker Description : Build, tag, push, or run Docker images, or run a Docker command. Task can be used with Docker or Azure Container registry. Version : 0.150.6 Author : Microsoft Corporation Help : [More Information]https://go.microsoft.com/fwlink/?linkid=848006)
============================================================================== [command]/usr/bin/docker build -f
/home/vsts/work/1/s/DockerTest/Dockerfile -t ihacontainers.azurecr.io/dockertest:6 /home/vsts/work/1/s/DockerTest Sending build context to Docker daemon 6.144kB Step 1/15 : FROM mcr.microsoft.com/dotnet/core/runtime:2.2-stretch-slim AS base 2.2-stretch-slim: Pulling from dotnet/core/runtime 743f2d6c1f65: Pulling fs layer 074da88b8de0: Pulling fs layer ac831735b47a: Pulling fs layer 3adcc844418d: Pulling fs layer 3adcc844418d: Waiting ac831735b47a: Download complete 743f2d6c1f65: Verifying Checksum 743f2d6c1f65: Download complete 074da88b8de0: Verifying Checksum 074da88b8de0: Download complete 3adcc844418d: Verifying Checksum zadcc844418d: Download complete 743f2d6c1f65: Pull complete 074da88b8de0: Pull complete ac831735b47a: Pull complete 3adcc844418d: Pull complete Digest: sha256:066c31b113b0a20e6155d3bd8a314563c688d2ec31c11d7e551af5bc2595f30c Status: Downloaded newer image for mcr.microsoft.com/dotnet/core/runtime:2.2-stretch-slim ---> c0f9ab44ecc1 Step 2/15 : WORKDIR /app ---> Running in 6d1a5f5600dd Removing intermediate container 6d1a5f5600dd ---> 527fcebeaf1f Step 3/15 : FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build 2.2-stretch: Pulling from dotnet/core/sdk c5e155d5a1d1: Pulling fs layer 221d80d00ae9: Pulling fs layer 4250b3117dca: Pulling fs layer 3b7ca19181b2: Pulling fs layer 3466298fc231: Pulling fs layer 310737d73ed1: Pulling fs layer dc981de74fae: Pulling fs layer 3b7ca19181b2: Waiting 3466298fc231: Waiting 310737d73ed1: Waiting dc981de74fae: Waiting 4250b3117dca: Verifying Checksum 4250b3117dca: Download complete 221d80d00ae9: Verifying Checksum 221d80d00ae9: Download complete 3466298fc231: Verifying Checksum 3466298fc231: Download complete c5e155d5a1d1: Verifying Checksum c5e155d5a1d1: Download complete 3b7ca19181b2: Verifying Checksum 3b7ca19181b2: Download complete c5e155d5a1d1: Pull complete 221d80d00ae9: Pull complete 310737d73ed1: Verifying Checksum 310737d73ed1: Download complete 4250b3117dca: Pull complete dc981de74fae: Verifying Checksum dc981de74fae: Download complete 3b7ca19181b2: Pull complete 3466298fc231: Pull complete 310737d73ed1: Pull complete dc981de74fae: Pull complete Digest: sha256:222cc0bb0bc93875ee0f6be626b2838beea838f65e53653e07c33eb9d00b0163 Status: Downloaded newer image for mcr.microsoft.com/dotnet/core/sdk:2.2-stretch ---> e4747ec2aaff Step 4/15 : WORKDIR /src ---> Running in a7ebcac87f68 Removing intermediate container a7ebcac87f68 ---> d7541674a9da Step 5/15 : COPY ["DockerTest/DockerTest.csproj", "DockerTest/"] COPY failed: stat /var/lib/docker/tmp/docker-builder158012929/DockerTest/DockerTest.csproj:no such file or directory

##[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

推荐答案

[error]COPY failed: stat/var/lib/docker/tmp/docker-builder158012929/DockerTest/DockerTest.csproj: 没有那个文件或目录

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

根据这个错误信息,错误发生在你的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 失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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