How to Build a Docker Image on Windows 10

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:

Sample Image

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.

Screenshot

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



Leave a reply



Submit