title: How can I solve COPY failed: file not found in build context or excluded in Azure Pipeline?
body: <p>I got stuck very interesting issue with azure pipeline. The issue is &quot;Forbidden path outside the build context&quot;.If you have an add line in the Dockerfile which points to another directory, the build of the image fails with the message &quot;Forbidden path&quot;.How can I solve this?</p>
  <p>I was recently attempting to Dockerize a C# project, so I added a docker folder to the project and created a simple Dockerfile to get started like below:</p>
  <p>Error:</p>
  <pre><code>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
   ---&gt; bd73c72c93a1
  Step 5/25 : WORKDIR /src
   ---&gt; Running in b457b1934a7e
  Removing intermediate container b457b1934a7e
   ---&gt; a50c5df6f929
  Step 6/25 : COPY [&quot;./src/xxxxx.Web/xxxxx.Web.csproj&quot;, &quot;src/xxxxx.Web/&quot;]
  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
  </code></pre>
  <p>DockerFiles/Dockerfile.xxxxx.Web:</p>
  <pre><code>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 [&quot;src/xxxxx.Web/xxxxx.Web.csproj&quot;, &quot;src/xxxxx.Web/&quot;]
  RUN dotnet restore &quot;src/xxxxx.Web/xxxxx.Web.csproj&quot;
  COPY . .
  WORKDIR &quot;/src/src/xxxxx.Web&quot;
  RUN dotnet build &quot;xxxxx.Web.csproj&quot; -c Release -o /app
  
  FROM build AS publish
  RUN dotnet publish &quot;xxxxx.Web.csproj&quot; -c Release -o /app
  
  FROM base AS final
  WORKDIR /app
  COPY --from=publish /app .
  ENTRYPOINT [&quot;dotnet&quot;, &quot;xxxxx.Web.dll&quot;]
  </code></pre>
  <p>azure-pipeline.yml:</p>
  <pre><code> # 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.BuildNumber)'
  
    # 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)
  
  </code></pre>
  <p>How can I solve &quot;COPY failed: Forbidden path outside the build context&quot;? <strong>I want to use Dockerfile in DockerFiles Directory.</strong></p>