docker - 在 Visual Studio 中使用相同的 docker 文件构建 docker 镜像的 Azure Pipeline 失败

标签 docker azure-devops dockerfile azure-pipelines

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

创建 docker 镜像失败
[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 pipeline 阶段引用来创建 docker 镜像。

 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"]

enter image description here

##[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 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 ##[section]Finishing: Build a container image

最佳答案

我通过使用与 Visual Studio 中相同的 dockerfile 将 buildContext 设置为“$(Build.Repository.LocalPath)”解决了该问题,而无需调整路径:

在 YAML-Konfiguration 中,我添加了以下行:

buildContext: '$(Build.Repository.LocalPath)'

关于docker - 在 Visual Studio 中使用相同的 docker 文件构建 docker 镜像的 Azure Pipeline 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56386812/

相关文章:

docker - 使用 docker/build-push-action 在 GitHub Actions 中本地构建 docker 镜像

git - 当 VSTS 中 CI 构建失败时如何从 git 恢复提交

azure - 如何在azure devops模板任务中参数化azureSubscription

azure-devops - 重新部署Azure Functions ARM模板会删除我发布的函数

docker - 如何确保我的 docker 镜像/容器在 100 年后仍然可以工作?

ubuntu - 正确安装了 Dockerfile 依赖项,但生成的图像没有它

Docker Redis - 播种数据 - 无法通过 Dockerfile 或 shell 脚本执行 redis-cli

mysql - WordPress和mysql pod部署正确,但我的浏览器未显示wordpress

postgresql - 在 centos docker 图像上初始化 postgres 失败,无法获得 D-Bus 连接 : Operation not permitted

docker - Dockerfile中的复制