3
votes

I want to create a Docker Image that can be hosted on Azure App Services for Windows. My application is based on ASP.NET Core 2.1 and according to the official list of .NET images images, I should be able to simply use microsoft/dotnet:2.1-aspnetcore-runtime.

I can build the Dockerfile on a Windows machine successfully and was able to run it there without issues. But after uploading it to Docker Hub and setting it as the App Service's Docker Image, I get the following error message:

Cannot run this Operating System/Version in Windows Containers. Maximum supported OS version is 10.0.14393.9999.

According to the Azure App Services Documentation, it should support the microsoft/dotnet:2.1-aspnetcore-runtime as one of the pre-installed parent images.

When inspecting my Docker Image, I found, that the used image seems to be too new for Azure App Services:

"Architecture": "amd64",
"Os": "windows",
"OsVersion": "10.0.17134.285" <-- too new

After some research, I found in this blog post, that Azure App Services on Windows might only accept microsoft/dotnet:2.1-aspnetcore-runtime-nanoserver-sac2016 image. So I tried to rebuild the Docker Image with these.

This time, the App Service accepted the image, but was unable to start it, throwing the following logs:

02/10/2018 14:15:09.437 ERROR - Site: rothiewindockerdemo - Image pull reported error. Image: robinmanuelthiel/contosomaintenance-api:latest-windows-sac2016. failed to register layer: re-exec error: exit status 1: output: remove \\?\C:\DockerData\windowsfilter\93b716197958ceb58006ff3d978fcb3202f7866d00d6d8d69513cf0478a17a7f\UtilityVM\Files\Windows\servicing\Packages\Microsoft-UtilityVM-Core-Package~31bf3856ad364e35~amd64~~10.0.14393.0.cat: The process cannot access the file because it is being used by another process.
02/10/2018 14:15:09.437 INFO - Site: rothiewindockerdemo - Image: robinmanuelthiel/contosomaintenance-api:latest-windows-sac2016
Custom Registry: https://index.docker.io

02/10/2018 14:15:09.439 ERROR - Site: rothiewindockerdemo - Pull image completed but it was not found locally. Image: robinmanuelthiel/contosomaintenance-api:latest-windows-sac2016
02/10/2018 14:15:09.441 WARNING - Site: rothiewindockerdemo - Attempt 1 to start container was unsuccessful. Maximum attempts: 3. 
02/10/2018 14:15:09.568 INFO - Site: rothiewindockerdemo - Purging after container failed to start
02/10/2018 14:15:09.582 INFO - Site: rothiewindockerdemo - Purging pending logs after stopping container

So what is the correct Windows Docker Base Image for ASP.NET Core 2.1 Docker Containers on Azure App Services?

That's my Dockerfile:

#######################################################
# Step 1: Build the application in a container        #
#######################################################

# Download the official ASP.NET Core SDK image 
# to build the project while creating the docker image
FROM microsoft/dotnet:2.1-sdk as build
WORKDIR /app

# Restore NuGet packages
COPY *.csproj .
RUN dotnet restore

# Copy the rest of the files over
COPY . .

# Build the application
RUN dotnet publish --output /out/ --configuration Release

#######################################################
# Step 2: Run the build outcome in a container        #
#######################################################

# Download the official ASP.NET Core Runtime image
# to run the compiled application
FROM microsoft/dotnet:2.1-aspnetcore-runtime

WORKDIR /app

# Open HTTP and HTTPS ports
EXPOSE 80
EXPOSE 443

# Copy the build output from the SDK image
COPY --from=build /out .

# Start the application
ENTRYPOINT ["dotnet", "MyApp.dll"]
3
Do you delete the former image which base image is too new when you create the new image?Charles Xu

3 Answers

5
votes

The issue lies in the fact that microsoft/dotnet:2.1-aspnetcore-runtime is a multi-architecture base image. This means that Docker build will pick the best architecture for your local machine (the machine where you are building your docker image). I assume that your local machine is Windows 10 April 2018 Update (Version 1803 - Whose build number 17134.407). As of now, we only support images based off of Windows Server 2016 (Version 1709, up to build number 14393.XX).

In order to “force” a specific version, please use this base image instead: microsoft/dotnet:2.1-aspnetcore-runtime-nanoserver-sac2016. You can check all the available tags in https://hub.docker.com/r/microsoft/dotnet/

We will work on calling this out specifically in our documentation.

1
votes

Is important to mention that Windows Containers on App Service is currently in Preview.

The validation on the portal "Cannot run this Operating System/Version in Windows Containers. Maximum supported OS version is 10.0.14393.9999." is shown because we are running the servers with Windows Server 2016 RS1 and currently can't run containers for RS3+. We are currently working on enabling them, but we don't have an ETA to share at this point.

If the validation passes, it means that the specified image should work fine and the issue you are seeing is not directly related to the image. It is a bug in the platform and it seems similar to the issue reported here: https://github.com/Microsoft/hcsshim/issues/155

We will continue investigating and thanks for reporting the issue

0
votes

The answer above that was marked as an answer is not correct. It leads you to believe that using microsoft/dotnet:2.1-aspnetcore-runtime-nanoserver-sac2016 will solve your problems, but it won't. I tested this on Azure Container instances, and it does not work.

The solutions is this: when you get OsVersionNotSupported it means that the image was create with windows version that is not supported, and Microsoft currently does not support any SAC versions (SAC is Semi-Annual Channel). So versions like 1709 and 1803 will NOT WORK. Also the "solution" above is not going to work, since it uses that tag of SAC2016.

For all tags that you can use in docker file, go here: https://github.com/dotnet/dotnet-docker/blob/master/TAGS.md

You need to go to https://docs.microsoft.com/en-us/azure/container-instances/container-instances-troubleshooting and read the section "OS version of image not supported". It clearly states that you need to "...always deploy Windows Server 2016 (LTSC)-based images...".