0

I am currently working with the azure build pipeline to build my .NET application and create docker image using self-hosted agent and docker desktop. after creating the image, image will be pushed to Azure Container Registry (ACR). But, when my pipeline is running it's failed to build the image, because my self-hosted agent couldn't find the docker daemon, though my local docker-desktop is running properly. Please check the steps that I have done and want to.

enter image description here

Pipeline:

enter image description here

Dockerfile

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["Project.API/Project.API.csproj", "Project.API/"]
RUN dotnet restore "Project.API/Project.API.csproj"
COPY . .
WORKDIR "/src/Project.API"
RUN dotnet build "Project.API.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Project.API.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Project.API.dll"]

Error

enter image description here

sebu
  • 2,824
  • 1
  • 30
  • 45

1 Answers1

1

I have tried to reproduce it in my environment and got the below result.

Note - I suspect the error you are getting is due to Azure Agent. There might be a case the it did not installed properly.

Step 1: Go to ADO Organization > Agent pools > Add a pool and create a new one. enter image description here

enter image description here

Step 2: Go to test pool> New agent and follow the steps mentioned there. enter image description here

Download the agent to your machine and run the displayed commands in the power shell.

PS C:\> mkdir agent ; cd agent
PS C:\agent> Add-Type -AssemblyName System.IO.Compression.FileSystem ; [System.IO.Compression.ZipFile]::ExtractToDirectory("$HOME\Downloads\vsts-agent-win-x64-2.217.2.zip", "$PWD")
PS C:\agent> .\config.cmd

Please select the options as shown below while configuring the azure agent in the machine.

enter image description here

Step 3: Install and configure Docker windows and verify it is up and running using the below command as shown.

$docker run hello-world

enter image description here

Step 4: Build the source code with Dockerfile in the Azure pipeline. I have a basic dotnet web application with Dockerfile and below is my docker build pipeline. [![enter image description here][6]][6]

pool: testpool
steps:
  - task: Docker@2
    displayName: Docker build
    inputs:
      command: build
      Dockerfile: devopswebapp/Dockerfile

Below is the result after running the pipeline.

enter image description here

Sourav
  • 814
  • 1
  • 9