Twitter Facebook Google+ LinkedIn
Fri, Aug 18, 2017

Docker Windows Image for IoT Edge

We were in a scenario where we wanted to enable IoT Edge to run on a Windows Server Core docker container so that we could run some scenarios. We couldn’t find a good way of doing this all in one Dockerfile, but found a way to merge a few Dockerfiles into one.

The gist of the cleaned up result is below:

Looking more closely at the Dockerfile, let’s walk through what each section means.

FROM microsoft/windowsservercore

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

The first line tells Docker to utilize the windowsservercore base image. The second line tells Docker to switch the command shell to PowerShell and to stop on any error messages, but continue on progress updates.

RUN Invoke-WebRequest -Uri "" -OutFile NDP47-KB3186497-x86-x64-AllOS-ENU.exe
RUN .\NDP47-KB3186497-x86-x64-AllOS-ENU.exe /q
RUN del .\NDP47-KB3186497-x86-x64-AllOS-ENU.exe

The first RUN command above downloads the latest version of .NET Framework 4.7 and places it to an .exe file. The second line runs the .exe with the ‘/q’ or quiet flag to avoid output and installer window. The third RUN command removes the excess .exe after the full framework installs.


RUN Invoke-WebRequest $Env:DOTNET_SDK_DOWNLOAD_URL -OutFile; \
Expand-Archive -DestinationPath $Env:ProgramFiles\dotnet; \
Remove-Item -Force

RUN setx /M PATH $($Env:PATH + ';' + $Env:ProgramFiles + '\dotnet')

The first two lines set up environment variables for .NET Core. The RUN Invoke-WebRequest line downloads the .NET Core SDK. Expand-Archive is a PowerShell way to unzip a zip file, and we can unzip the downloaded .zip directly into program files. The Remove-Item command deletes the .zip file using PowerShell. The last RUN setx command here, sets the path environment variable globally (not just for this shell) to point to the new dotnet folder in Program Files.

RUN New-Item -Type Directory warmup; \
cd warmup; \
dotnet new; \
cd ..; \
Remove-Item -Force -Recurse warmup

These next few lines are here just to warm the dotnet cli up so that future calls aren’t initially slow (useful to avoid long startup times).


RUN Invoke-WebRequest $('{0}/node-v{0}' -f $env:NODE_VERSION) -OutFile ''; \
Expand-Archive -DestinationPath C:\ ; \
Rename-Item -Path $('C:\node-v{0}-win-x64' -f $env:NODE_VERSION) -NewName 'C:\nodejs'


RUN New-Item $($env:APPDATA + '\npm') ; \
$env:PATH = 'C:\nodejs;{0}\npm;{1}' -f $env:APPDATA, $env:PATH ; \
[Environment]::SetEnvironmentVariable('PATH', $env:PATH, [EnvironmentVariableTarget]::Machine)

This is setting an environment variable for NODE_VERSION, then downloading that version of Node through .zip file. The final step then extracts those contents to C:\nodejs and deletes the .zip file.

RUN Invoke-WebRequest $('') -OutFile vcredist.exe
RUN .\vcredist.exe /q
RUN del .\vcredist.exe

The last few lines here download the vc_redist_x64 and install it (useful for IoT Edge).

Twitter Facebook Google+ LinkedIn