Create Docker Image of .NET Core 3.1 app on Windows 10 Pro and pull it to Windows Server 2016
There's a difference between what is supported and what is available. Running .NET Core in a container on Windows Server 2016 is supported but there is not an available image for it. You're left to define your own.
Your options for what Windows container versions can run on a Windows Server 2016 host are limited to only Windows Server 2016 containers. This means you cannot run a nanoserver:1809
container on a Server 2016 host, for example. This is illustrated in the Windows container version compatibility matrix:
Note that nanoserver:sac2016
has long been out of support so it would not be a recommended base image. There is not any currently supported tag for Nano Server on 2016. Instead, it'd be recommended to use Windows Server Core. The servercore:ltsc2016
is your best option for a supported tag.
Here's an example of how you would install .NET Core on a Server Core image:
# escape=`
FROM mcr.microsoft.com/windows/servercore:ltsc2016
RUN powershell -Command `
$ErrorActionPreference = 'Stop'; `
$ProgressPreference = 'SilentlyContinue'; `
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;
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 aspnetcore; `
Remove-Item -Force dotnet-install.ps1 `
&& setx /M PATH "%PATH%;C:\Program Files\dotnet"
Further resources:
- .NET install script
- Methods of installing .NET in a container
UPDATE
Here's an example of how this would be defined using a Dockerfile generated by Visual Studio:
# escape=`
FROM mcr.microsoft.com/windows/servercore:ltsc2016 AS base
# Install ASP.NET Core 3.1
RUN powershell -Command `
$ErrorActionPreference = 'Stop'; `
$ProgressPreference = 'SilentlyContinue'; `
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;
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 aspnetcore; `
Remove-Item -Force dotnet-install.ps1 `
&& setx /M PATH "%PATH%;C:\Program Files\dotnet"
WORKDIR /app
EXPOSE 80
EXPOSE 8001
FROM mcr.microsoft.com/windows/servercore:ltsc2016 AS build
# Install .NET Core 3.1 SDK
RUN powershell -Command `
$ErrorActionPreference = 'Stop'; `
$ProgressPreference = 'SilentlyContinue'; `
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;
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; `
Remove-Item -Force dotnet-install.ps1 `
&& setx /M PATH "%PATH%;C:\Program Files\dotnet"
WORKDIR /src
COPY ["WebApi.csproj", "."]
RUN dotnet restore "WebApi.csproj"
COPY . .
WORKDIR "/src/"
RUN dotnet build "WebApi.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "WebApi.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebApi.dll"]
How do I create a Docker container on a Windows 10 PC to run on a Raspberry Pi 4
You have to specify the platform. Either in your Dockerfile, or from the command line.
FROM --platform=linux/arm/v7 python:3.6-stretch
You might need to use BuildKit or enable experimental features for your Docker daemon if you want to be able to set the platfrom from the command line:
DOCKER_BUILDKIT=1 docker build --platform=linux/arm/v7 .
You need to have Qemu and docker/binfmt installed to be able to build ARM images on x86_64. The installation process is explained here: https://www.docker.com/blog/getting-started-with-docker-for-arm-on-linux/
On Linux, you have to install this yourself. From what I've gathered, it's included with Docker for Windows.
Unable to build a Docker image on Windows 10
I had the same problem. But when I switched to Linux containers it helped.
If you use Linux containers than you will see "Switch to Windows containers..." when you press RMB on Docker.
Dockerd can't perform `apt-get update` when building image on windows
I believe your problem is that dockerd
on Windows will try to run Windows containers, not Linux. When using Docker desktop, it changes the context to use WSL 2 for Linux containers and HCSv1 for Windows containers. I'm not sure if you can set up dockerd
directly. What is the environment? Is it a Windows client or Server?
Related Topics
What Is the Explanation of This X86 Hello World Using 32-Bit Int 0X80 Linux System Calls from _Start
How Do 2 or More Fork System Calls Work
Define Function in Unix/Linux Command Line (E.G. Bash)
How to Confirm Sftp File Delivery
How to Non-Interactively Turn on Features in a Linux Kernel .Config File
How to Get Multi-Line String Between Two Braces Containing a Specific Search String
-O in Linux Terminal (Dash O); What Does It Mean
How to Rename Multiple Files Beginning with a Unix Timestamp - Imapsync Issue
How to Use Variables with Brace Expansion
Using Gnu/Linux System Call 'Splice' for Zero-Copy Socket to Socket Data Transfers in Haskell
How to Pass Arguments with Special Characters to Call Shell Script
Why Characters Received in Serial Connection Only After Pressing Enter
What Does 'Set -O Errtrace' Do in a Shell Script
Hosting Two Website Under One Web App - Azure Services
How to Use Netcat for Windows to Send a Binary File to a Tcp Connection
Ansible Ad-Hoc Command with Direct Host Specified - No Hosts Matched