Skip to content
  • Home

Jack Pye

A blog about all things cloud related

Azure DevOps Docker Pipeline to Azure Container Registry

January 21, 2024 by Jack Pye

While undertaking some testing within my Azure Subscription i was looking for a way to store a .net application within a Azure Repository and from there be able to generate a Docker image via a Azure Pipeline that would then deploy it directly into my Azure Container Registry.

Azure Repository Configuration

A private Azure Repository will need to be created to store the .net application files within.

As can be seen in the screenshot below a Docker Repo has been created with the .net application copied into it.

DockerFile Creation

Now that the .net files have been created within the Azure Repo we need to create the DockerFile. This will be created within the app folder.

The configuration for the DockerFile has been listed below. The sections highlighted in Orange will need to be adjusted dependent on the requirements that the deployment has.

# Set the version of dotnet to use. Opening the .csproj file will show you the version
FROM  mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
#Set the Workdir to the folder within the repo with the .csproj located
WORKDIR /app

# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out

# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
COPY --from=build-env /app/out .
#The JacksFirst.dll needs to match the name of the CSPROJ within the app folder. 
ENTRYPOINT ["dotnet", "JacksFirst.dll"]

Azure Pipelines

Now that we have created the DockerFile we can move onto the Azure Pipelines that will undertake the automated deployment into the Azure Container Registry.

At this point you are able to select the Container Registry and set the image name that you would like to be used for the application. At the bottom you are able to select the location of the Dockerfile to enable the creation of the docker image.

At this point the wizard creates a service connection to the Azure Container Registry automatically.

The wizard that was run earlier generates the following Azure Pipelines.yml. This contains the dockerRegistryServiceConnection which connects directly to the Azure Container Registry.

# Docker
# Build and push an image to Azure Container Registry
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker

trigger:
- master

resources:
- repo: self

variables:
  # Container registry service connection established during pipeline creation
  dockerRegistryServiceConnection: '****'
  imageRepository: 'dotnethelloworldapp'
  containerRegistry: 'jackpyedemo.azurecr.io'
  dockerfilePath: '$(Build.SourcesDirectory)/app/Dockerfile'
  tag: '$(Build.BuildId)'

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

stages:
- stage: Build
  displayName: Build and push 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)

Related

Post navigation

Previous Post:

Azure App Service Linux Container – Confirm Outbound Public IP

Next Post:

Configuring Private DNS In Azure

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *


Recent Posts

  • Configuring Private DNS In Azure
  • Azure DevOps Docker Pipeline to Azure Container Registry
  • Azure App Service Linux Container – Confirm Outbound Public IP
  • Stopping the Azure Application Gateway

Archives

  • March 2025
  • August 2022
  • May 2022

Categories

  • App Service
  • Application Gateway
  • Azure
  • Azure Container Registry
  • Azure DevOps
  • Azure Pipelines
  • Docker
  • Powershell
  • Private DNS
  • Terraform

Follow Me On LinkedIn

  • LinkedIn
© 2025 Jack Pye | WordPress Theme by Superbthemes