Wednesday, August 8, 2018

Docker: Windows Server 2016, ASP.NET Core 2.1 Runtime Image with Node

I wanted to have a docker image with Windows Server 2016 having ASP.NET Core 2.1 Runtime and Node installed, and didn’t find any official image that has them all (maybe there is and it’s just I couldn’t find).

But managed to get one created with some little extra steps.
# escape=`
# The escape directive sets the character used to escape and it's used both to escape characters in a line, 
# and to escape a newline. Below we have some commands spanning across multiple lines, so we need this.
# Note: It needs to be menioned before anything, yes, even before a comment.
 
FROM microsoft/dotnet:2.1.2-aspnetcore-runtime-nanoserver-sac2016
 
# The default shell on Windows is ["cmd", "/S", "/C"], Changing to PowerShell
SHELL["powershell", "-Command", "$ErrorActionPreference = 'Stop';"]
 
# Current Node LTS Version as of 07/08/2018
ENV NODE_VERSION 8.11.3
 
# Make sure to use the SHA of the specified Node version 
ENV NODE_VERSION_SHA 91b779def1b21dcd1def7fc9671a869a1e2f989952e76fdc08a5d73570075f31
 
# PowerShell commands to download and extract  
RUN Invoke-WebRequest https://nodejs.org/dist/v$Env:NODE_VERSION/node-v$Env:NODE_VERSION-win-x64.zip -OutFile node.zip; `
    if ((Get-FileHash node.zip -Algorithm sha256).Hash -ne $Env:NODE_VERSION_SHA) { `
        Write-Host 'CHECKSUM VERIFICATION FAILED!'; `
        exit 1; `
    }; `
    `
    Expand-Archive node.zip -DestinationPath node-temp; `
    Move-Item node-temp/node-v$Env:NODE_VERSION-win-x64 $Env:ProgramFiles/nodejs; `
    Remove-Item -Force node.zip; `
    Remove-Item -Force node-temp
 
# Setting Node to Path
RUN setx /M PATH $($Env:PATH + ';' + $Env:ProgramFiles + '/nodejs')
 
# Next steps is omitted

Hope this helps someone having the same requirement.

Happy Coding.

Regards,
Jaliya

No comments:

Post a Comment