No description
  • CSS 45.3%
  • HTML 32.7%
  • C# 13.5%
  • JavaScript 8.5%
Find a file
2026-04-28 12:29:44 +02:00
BlazorDemo.Backend.Api prepare docker image publishing 2026-04-28 12:29:44 +02:00
BlazorDemo.Frontend.InteractiveServer prepare docker image publishing 2026-04-28 12:29:44 +02:00
BlazorDemo.Frontend.Shared.Infrastructure state from part 2 2026-04-28 11:03:03 +02:00
BlazorDemo.Frontend.Shared.Ui state from part 2 2026-04-28 11:03:03 +02:00
.editorconfig state from part 2 2026-04-28 11:03:03 +02:00
.gitignore state from part 2 2026-04-28 11:03:03 +02:00
BlazorDemo.sln state from part 2 2026-04-28 11:03:03 +02:00
README.md update README 2026-04-28 12:27:12 +02:00

Step 3 - Dockerize

Prerequisites

basic familiarity with

  • dotnet cli
  • c#
  • docker
  • microsoft azure
  • azure container registry (acr) for docker images

How does our azure look so far?

https://portal.azure.com/browse/Microsoft.ContainerRegistry%2Fregistries

Get the Azure Container Registry Ready

create the acr

login

az login --use-device-code

create testing resource group and container registry

az group create --name rgblazordemo --location westeurope && az acr create --resource-group rgblazordemo --name crblazordemo --sku Basic

check if it worked

cli

az acr repository list --name crblazordemo

successful if []

in the portal

https://portal.azure.com/browse/Microsoft.ContainerRegistry%2Fregistries

naming: https://learn.microsoft.com/en-us/azure/cloud-adoption-framework/ready/azure-best-practices/resource-abbreviations#containers

logging into the docker container registry

GOAL: being able to do dotnet publish without issues

Option 1 - use az acr login --name crblazordemo

the Azure CLI does two things:

  • Gets an access token from Azure for your Azure Container Registry
  • Passes that token to Docker as if you had done a docker login

Internally, its roughly equivalent to:

docker login crblazordemo.azurecr.io \
  --username 00000000-0000-0000-0000-000000000000 \
  --password <access-token>

Option 2 - username/password account for docker login

enable a built-in username/password account with --admin-enabled so we can do docker login crblazordemo.azurecr.io --username ... --password ...

az acr update --name crblazordemo --admin-enabled true

get the credentials

az acr credential show --name crblazordemo

expected output

{
  "passwords": [
    {
      "name": "password",
      "value": "a$$worD"
    },
    {
      "name": "password2",
      "value": "a$$worD2"
    }
  ],
  "username": "crblazordemo"
}

What changes after running it

  • Before: Only Azure identity-based auth (e.g. az acr login)

  • After: You also have static credentials (user/password)

When to use az acr login

  • Production systems
  • CI/CD pipelines
  • Reason: it is a shared credential (no per-user tracking, harder to rotate securely).

When to use the username/password account

  • Local development
  • Simple scripts
  • Quick testing

Publish the docker images

prepare images

BlazorDemo.Backend.Api/BlazorDemo.Backend.Api.csproj

<PropertyGroup>
	<ContainerImageTags>latest</ContainerImageTags>
	<ContainerRepository>ramboe/blazordemo-backend-api</ContainerRepository>
	<ContainerRegistry>crblazordemo.azurecr.io</ContainerRegistry>
</PropertyGroup>

BlazorDemo.Frontend.InteractiveServer/BlazorDemo.Frontend.InteractiveServer.csproj

<PropertyGroup>
	<ContainerImageTags>latest</ContainerImageTags>
	<ContainerRepository>ramboe/blazordemo-frontend-interactiveserver</ContainerRepository>
	<ContainerRegistry>crblazordemo.azurecr.io</ContainerRegistry>
</PropertyGroup>

container properties explained here

docker login

docker login crblazordemo.azurecr.io --username crblazordemo --password <yourpassword>

publish images

dotnet publish BlazorDemo.Frontend.InteractiveServer --os linux --arch x64 /t:PublishContainer -c Release & dotnet publish BlazorDemo.Backend.Api --os linux --arch x64 /t:PublishContainer -c Release

explained

Part Meaning
dotnet publish Compiles the project and produces deployable output (Release by default if configured)
BlazorDemo.Frontend.InteractiveServer Project (folder or .csproj) to publish
--os linux Target operating system for the output (affects runtime + container base image)
--arch x64 Target CPU architecture
/t:PublishContainer MSBuild target that builds a container image instead of just files

since we configured the container registry in the .csproj files, this command performs an actual docker build and docker push under the hood (other wise the image would just be stored locally)

check repositories again

az acr repository list --name crblazordemo