Why does .NET Framework sample image throw error when running in Azure Container Instances from Azure Container Registry?

534 views Asked by At

I'd like to run a .NET Framework (4.8) console app on Azure Container Instances.

Starting from https://github.com/microsoft/dotnet-framework-docker/tree/master/samples/dotnetapp

If I create the ACI directly:

az container create --resource-group mygroup --name nethowdy --image mcr.microsoft.com/dotnet/framework/samples:dotnetapp --restart-policy Never --os-type Windows

... it runs as expected - i.e., it completes successfully, and the output is correct:

az container logs --resource-group mygroup --name nethowdy

So far, so good.

Then I cloned https://github.com/microsoft/dotnet-framework-docker and went to the samples/dotnetapp folder. Works fine building/running docker locally.

However, when I try to build that sample image into ACR, I can't get it to work. Specifically, I do this:

az acr build --registry myreg --image nethowdy --file Dockerfile.basic --platform windows .

That build process succeeds, and everything looks good. But when I try to create the container from it, it fails:

az container create --resource-group mygroup --name nethowdy --image myreg.azurecr.io/nethowdy --restart-policy Never --os-type Windows

Specifically, I get this error:

BadRequestError: Unsupported windows image version. Supported versions are 'Windows Server 2016 - Before 2B, Windows Server 2019 - Before 2B, Windows Server 2016 - After 2B, Windows Server 2019 - After 2B'

Can anyone tell me what I'm doing wrong? This is the base .NET Framework image, so it should be able to run on ACI - and it clearly does when I create the container from Microsoft's image instead of mine. Is this an auth problem with ACI/ACR or something like that? I'd appreciate any clues.

EDIT: I've moved past the obstacle, so I'm not stuck - but I'm still figuring out details of "the problem" ... I'll post my own answer soon to help the next person

2

There are 2 answers

1
Charles Xu On

The error already shows you the reason: unsupported Windows image version. ACI does not support all the windows images, you can get the details here about the windows image that supported in the ACI.

0
Robert Brend On

The issue is as pointed out before that the version of windows used to make the image is not supported in ACI.

This link gives an indication of supported O.S Versions: https://learn.microsoft.com/en-gb/azure/container-instances/container-instances-faq

There are a number of commands which are suggested to find out your O.S. in your container. Make sure you run docker exec -it {container name} cmd first replacing {container name} with either the id or the name of the container. This will then allow you to run commands e.g. ver in cmd to get the version.

Finally the reason you are likely getting this problem is because in your docker file the base image you haven't specified what operating system you want to use.

e.g. FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base

If you check out the documentation for the image on docker hub

e.g. https://hub.docker.com/_/microsoft-dotnet-aspnet/

You will find information about what O.S. image has been used to build the image. Find one which is compatible with ACI and adjust your base image

e.g. FROM mcr.microsoft.com/dotnet/aspnet:5.0.5-windowsservercore-ltsc2019 AS base