title: What's the correct Windows Base Image for ASP.NET Core 2.1 Docker Containers on Azure App Services
body: <p>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 <a href="https://hub.docker.com/r/microsoft/dotnet/" rel="nofollow noreferrer">official list of .NET images images</a>, I should be able to simply use <code>microsoft/dotnet:2.1-aspnetcore-runtime</code>.</p>
  
  <p>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:</p>
  
  <blockquote>
    <p>Cannot run this Operating System/Version in Windows Containers.
    Maximum supported OS version is 10.0.14393.9999.</p>
  </blockquote>
  
  <p>According to the <a href="https://docs.microsoft.com/en-us/azure/app-service/app-service-web-get-started-windows-container#use-a-different-parent-image" rel="nofollow noreferrer">Azure App Services Documentation</a>, it should support the <code>microsoft/dotnet:2.1-aspnetcore-runtime</code> as one of the pre-installed parent images.</p>
  
  <p>When inspecting my Docker Image, I found, that the used image seems to be too new for Azure App Services:</p>
  
  <pre><code>"Architecture": "amd64",
  "Os": "windows",
  "OsVersion": "10.0.17134.285" &lt;-- too new
  </code></pre>
  
  <p>After some research, I <a href="https://blogs.msdn.microsoft.com/benjaminperkins/2018/09/18/publish-a-web-app-for-containers-windows-docker-image/" rel="nofollow noreferrer">found in this blog post</a>, that Azure App Services on Windows might only accept <code>microsoft/dotnet:2.1-aspnetcore-runtime-nanoserver-sac2016</code> image. So I tried to rebuild the Docker Image with these.</p>
  
  <p>This time, the App Service accepted the image, but was unable to start it, throwing the following logs:</p>
  
  <pre><code>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
  </code></pre>
  
  <p><strong>So what is the correct Windows Docker Base Image for ASP.NET Core 2.1 Docker Containers on Azure App Services?</strong></p>
  
  <p>That's my <code>Dockerfile</code>:</p>
  
  <pre><code>#######################################################
  # 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"]
  </code></pre>