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
2
Answers
Ok easy one,
So you have two parameters
Build context is where the build is going to essentially be built from and dockerfile is the location of the docker file.
When your pipeline gets to that task you will be executing from /home/vsts/work/1/s/ so your path to the docker file will be as below, if you a dropping the whole repo.
ProjectA/RepoB/Services/ServiceC/ServiceC.API/Dockerfile
But I am going to assume ProjectA is the Team Project and RepoB is the name of the git/TFVC repo, so not use is the pipeline folder drop.
Services/ServiceC/ServiceC.API/Dockerfile
Location on the build agent would be
/home/vsts/work/1/s/Services/ServiceC/ServiceC.API/Dockerfile
I wouldn’t use wildcards in the buildcontext, I always set my build context at solution level, but it all depends on how you dockerfile is constructed.
You will then second task for the next dockerfile
If you want both Services in a single container this is not the way to do it, but that is totally separate question.
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 fordockerfile
.The pipeline works then:
The
buildContext
is useful when you havecontainerRegistry
defined.