title: Create Docker Image of .NET Core 3.1 app on Windows 10 Pro and pull it to Windows Server 2016
body: <p>I have successfully created Docker images that contain .NET Core 3.1 projects and am running them in Windows Containers on my local Windows 10 Pro machine. I am using Windows Containers, not Linux.</p>
  <p>I want to be able to pull them to a Windows 2016 Server machine (not a VM). I have Docker EE installed on the Windows 2016 Server and it is running. docker version reports Version 20.10.0.</p>
  <p>According to the following, there are not any supported .NET Core images available for Windows Server 2016. <a href="https://stackoverflow.com/questions/57912243/no-matching-manifest-for-windows-amd64-server-2016">no matching manifest for windows/amd64 Server 2016</a></p>
  <p>If that is true, am I trying to do something that is impossible? Or simply not supported?</p>
  <p>I am new at this, but from what I understand .NET Core apps require nanoserver 1809 or higher to be installed in the host. If that is incorrect, let me know...</p>
  <p>NOTE: I have successfully pulled this to the Windows 2016 Server:</p>
  <pre><code>docker pull mcr.microsoft.com/windows/nanoserver:sac2016
  </code></pre>
  <p>But from what I read here, <a href="https://github.com/dotnet/dotnet-docker/issues/1041" rel="nofollow noreferrer">https://github.com/dotnet/dotnet-docker/issues/1041</a>, .NET Core 3.x is no longer supported on that base.</p>
  <p><strong>ISSUE 1</strong></p>
  <p>When I run the following on the Windows 2016 Server, I get the error &quot;no matching manifest for windows/amd64 10.0.14393 in the manifest list entries&quot;.</p>
  <pre><code>docker pull mcr.microsoft.com/windows/nanoserver:1809
  </code></pre>
  <p>According to this page, I should be able to pull that:  <a href="https://docs.microsoft.com/en-us/virtualization/windowscontainers/deploy-containers/deploy-containers-on-server" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/virtualization/windowscontainers/deploy-containers/deploy-containers-on-server</a></p>
  <p><strong>ISSUE 2</strong></p>
  <p>From what I read it looks like I will need to create my images or at least run them in containers in &quot;hyperv&quot; isolation mode. Correct? Or can the docker host itself run a different version of the OS (like nanoserver 1809 or whatever)? I'm using Visual Studio to build all of this locally and am also using docker-compose where I can specify the isolation mode in the yml file. But I don't know how to do that when I publish my images to my Docker Hub through VS.NET. My images publish successfully, but then when I try to use docker pull to bring them down to the Windows 2016 Server I get this error:</p>
  <pre><code>a Windows version 10.0.19042-based image is incompatible with a 10.0.14393 host
  </code></pre>
  <p><strong>ISSUE 3</strong></p>
  <p>Related to the above error, I guess I need to include an older Windows base version in my image? I have added the following to my dockerfile:</p>
  <pre><code>FROM mcr.microsoft.com/windows/nanoserver:1809
  </code></pre>
  <p>But it didn't seem to do anything. When I run the project in VS.NET, I see this when I inspect the container:</p>
  <pre><code>OsVersion: 10.3.19042.867
  </code></pre>
  <p>My goal for a proof of concept is simply to:</p>
  <ol>
  <li>Create an image of a .NET Core 3.1 web api project on my Windows 10 Pro laptop</li>
  <li>Pull it to a Windows 2016 Server and run it in a Docker Container.</li>
  </ol>
  <p>#1 all works on my laptop. Getting #2 accomplished is where I'm really confused.</p>
  <p>Thanks, Brent</p>
  <p><strong>UPDATE</strong></p>
  <p>Below are the Dockerfile and commands I use to build the image, run it in a container and inspect it. NOTE that with this Dockerfile, in the interactive command prompt I do now see:</p>
  <ul>
  <li>the correct OS ver: 10.0.14393</li>
  <li>the file system does contain my .Net solution, project and my source code.</li>
  </ul>
  <p>I've just taken what MattT provided and added it to the beginning of the Dockerfile that VS.NET generated when I added DockerSupport. I know I have goofed my Dockerfile up because it doesn't build / publish or run my webapi project (as it did prior to adding the new commands). I assume it has something to do with my FROM statements. I've read so much, but don't yet understand how layering works, among other things.</p>
  <pre><code># escape=`
  FROM mcr.microsoft.com/windows/servercore:ltsc2016 AS baseOS
  RUN powershell -Command [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12; $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest -UseBasicParsing -Uri https://dot.net/v1/dotnet-install.ps1 -OutFile dotnet-install.ps1; ./dotnet-install.ps1 -InstallDir '/Program Files/dotnet' -Channel 3.1 -Runtime dotnet; Remove-Item -Force dotnet-install.ps1 &amp;&amp; setx /M PATH &quot;%PATH%;C:\Program Files\dotnet&quot;
  COPY . .
  
  FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
  
  WORKDIR /app
  EXPOSE 80
  EXPOSE 8001
  
  FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
  WORKDIR /src
  COPY [&quot;WebApi.csproj&quot;, &quot;.&quot;]
  
  RUN dotnet restore &quot;WebApi.csproj&quot;
  COPY . .
  
  WORKDIR &quot;/src/&quot;
  RUN dotnet build &quot;WebApi.csproj&quot; -c Release -o /app/build
  
  FROM build AS publish
  RUN dotnet publish &quot;WebApi.csproj&quot; -c Release -o /app/publish
  
  FROM base AS final
  #FROM baseOS AS final
  WORKDIR /app
  COPY --from=publish /app/publish .
  ENTRYPOINT [&quot;dotnet&quot;, &quot;WebApi.dll&quot;]
  </code></pre>
  <p>docker commands I run:</p>
  <pre><code>docker build -f &quot;C:\Cabinet\Learning\EssApiProjects\src\Services\WebApi\Dockerfile&quot; --force-rm -t webapi:ltsc2016 --target baseOS &quot;C:\Cabinet\Learning\EssApiProjects\src\Services\WebApi&quot;
  
  docker run --env ASPNETCORE_ENVIRONMENT=Development -p 8001:80 --name webapi_ltsc2016 -it webapi:ltsc2016
  
  docker exec -it webapi_ltsc2016 cmd.exe 
  </code></pre>