程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了如何解决 COPY failed: file not found in build context or exclude in Azure Pipeline?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决如何解决 COPY failed: file not found in build context or exclude in Azure Pipeline??@H_197_1@ 开发过程中遇到如何解决 COPY failed: file not found in build context or exclude in Azure Pipeline?的问题如何解决?下面主要结合日常开发的经验,给出你关于如何解决 COPY failed: file not found in build context or exclude in Azure Pipeline?的解决方法建议,希望对你解决如何解决 COPY failed: file not found in build context or exclude in Azure Pipeline?有所启发或帮助;

我在 azure 管道中遇到了一个非常有趣的问题。问题是“构建上下文之外的禁止路径”。如果 Dockerfile 中有一条指向另一个目录的添加行,则映像构建失败并显示“禁止路径”消息。我该如何解决?

我最近尝试 Dockerize 一个 C# 项目,所以我在项目中添加了一个 docker 文件夹并创建了一个简单的 Dockerfile 以开始使用,如下所示:

错误:

f83e9c616794: Pulling fs layer
9887694812e5: Pulling fs layer
9887694812e5: Verifying checksum
9887694812e5: Download complete
dd4da9d953fb: Verifying checksum
dd4da9d953fb: Download complete
f83e9c616794: Verifying checksum
f83e9c616794: Download complete
dd4da9d953fb: Pull complete
f83e9c616794: Pull complete
9887694812e5: Pull complete
Digest: sha256:85ea9832ae26c70618418cf7c699186776ad066d88770fd6fd1edea9b260379a
Status: Downloaded newer image for mcr.microsoft.com/dotnet/sdk:5.0
 ---> bd73c72c93a1
Step 5/25 : workdir /src
 ---> Running in b457b1934a7e
Removing intermediate container b457b1934a7e
 ---> a50c5df6f929
Step 6/25 : copY ["./src/xxxxx.Web/xxxxx.Web.csproj","src/xxxxx.Web/"]
copY Failed: file not found in build context or excluded by .dockerignore: stat src/xxxxx.Web/xxxxx.Web.csproj: file does not exist
##[error]copY Failed: file not found in build context or excluded by .dockerignore: stat src/xxxxx.Web/xxxxx.Web.csproj: file does not exist
##[error]The process '/usr/bin/docker' Failed with exit code 1
Finishing: Build and push an image to container registry

Dockerfiles/Dockerfile.xxxxx.Web:

FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
workdir /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
workdir /src
copY ["src/xxxxx.Web/xxxxx.Web.csproj","src/xxxxx.Web/"]
RUN dotnet restore "src/xxxxx.Web/xxxxx.Web.csproj"
copY . .
workdir "/src/src/xxxxx.Web"
RUN dotnet build "xxxxx.Web.csproj" -c Release -o /app

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

FROM base AS final
workdir /app
copY --from=publish /app .
ENTRYPOINT ["dotnet","xxxxx.Web.dll"]

azure-pipeline.yml:

 # Deploy to Azure Kubernetes service
# Build and push image to Azure Container Registry; Deploy to Azure Kubernetes service
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker

trigger:
- test


variables:

  # Container registry service connection established during pipeline creation
  dockerRegistryserviceConnection: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
  imageRepository: 'xxxxxxxx'
  containerRegistry: 'xxxxxxxxxxxx.azurecr.io'
  dockerfilePath: '**/Dockerfiles/Dockerfile.xxxxx.Web'
  tag: '$(Build.build@R_874_10793@er)'

  # Agent VM image name
  vmImagename: 'ubuntu-latest'


stages:
- stage: Build
  displayname: Build stage
  jobs:
  - job: Build
    displayname: Build
    pool:
      vmImage: $(vmImageName)
    steps:
    - task: Docker@2
      displayname: Build and push an image to container registry
      inputs:
        command: buildAndPush
        repository: $(imageRepository)
        dockerfile: $(dockerfilePath)
        containerRegistry: $(dockerRegistryserviceConnection)
        Tags: |
          $(tag)

    - publish: manifests
      artifact: manifests

- stage: Deploy
  displayname: Deploy stage
  dependsOn: Build

  jobs:
  - deployment: Deploy
    displayname: Deploy-xxxxx.Web
    pool:
      vmImage: $(vmImageName)
    environment: 'xxxxx-5982.default'
    strategy:
      runOnce:
        deploy:
          steps:


          - task: Kubernetesmanifest@0
            displayname: Deploy to Kubernetes cluster
            inputs:
              action: deploy
              manifests: |
                $(Pipeline.WorkspacE)/manifests/deployment.eventhub.web.yml
                $(Pipeline.WorkspacE)/manifests/service.eventhub.web.yml
              containers: |
                $(containerRegistry)/$(imageRepository):$(tag)

如何解决“复制失败:构建上下文之外的禁止路径”? 我想在 Dockerfiles 目录中使用 Dockerfile。

解决方法@H_197_1@ @H_197_30@

您可以尝试在 Docker 任务中添加 buildContext 参数。

buildContext:构建上下文的路径

这是您可以参的 case。

大佬总结

以上是大佬教程为你收集整理的如何解决 COPY failed: file not found in build context or exclude in Azure Pipeline?全部内容,希望文章能够帮你解决如何解决 COPY failed: file not found in build context or exclude in Azure Pipeline?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。