I want to build the dockerfile of the .net service in my repo using Azure Pipeline. The folder structure is as follows:
|-- ProjectA
|-- |-- RepoB
| | -- .gitignore
| | -- Example.sln
| | -- Readme.md
| | -- Services
| | -- ServiceC
| | -- ServiceC.API
| | -- Program.cs
| | -- .
| | -- .
| | -- Dockerfile
| | -- ServiceD
| | -- ServiceD.API
| | -- Program.cs
| | -- .
| | -- .
| | -- Dockerfile
When I try to build the above dockerfiles with Azure pipeline, I get the following error::
[error]Unhandled: No Dockerfile matching /home/vsts/work/1/s/Dockerfile was found.
azure-pipelines.yml content as follows:
# Docker
# Build a Docker image
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker
trigger:
- test
resources:
- repo: self
variables:
tag: '$(Build.BuildId)'
stages:
- stage: Build
displayName: Build image
jobs:
- job: Build
displayName: Build
pool:
vmImage: ubuntu-latest
steps:
- task: Docker@2
displayName: Build an image for Lesson Service
inputs:
command: build
buildContext: 'Services/ServiceC/ServiceC.API/**'
dockerfile: 'Dockerfile'
tags: |
$(tag)
Can you help me solve the error? Thanks for your help.
Yaml file can be run and find the Dockerfile
I can reproduce the same with the folder structure and yaml:
To fix the error, you need to remove buildContext
parameter, and define file path for dockerfile
.
steps:
- bash: cat Services/ServiceC/ServiceC.API/Dockerfile
- task: Docker@2
displayName: Build an image for Lesson Service
inputs:
command: build
dockerfile: 'Services/ServiceC/ServiceC.API/Dockerfile'
tags: |
$(tag)
The pipeline works then:
The buildContext
is useful when you have containerRegistry
defined.