1

I asked this question originally at: https://github.com/aspnet/aspnet-docker/issues/349 as a part of the deprecation announcement, and I am hoping the SO community may have a good answer for this:

I am trying to use the windows side for a SPA build using the microsoft/dotnet:2.1-sdk. I know, I may be the only one trying to stay on the windows side for an ASP.NET Core Application, but our swarm initially will only have windows servers running in the native OS mode and not Hyper-V mode.

As a consequence, I need to install node.js for windows (because node.js/grunt/gulp are no longer a part of the image like they were in the microsoft/aspnetcore:2.0 image) and I tried:

RUN msiexec.exe /a https://nodejs.org/dist/v8.11.3/node-v8.11.3-x64.msi /quiet

but msiexec.exe isn't in the c:\windows\system32 of this image or in any other directory for that matter.

curl also is not in this image so I can't use that to download anything, and even if I could how do I un-tar or unzip anything?

I can't run a powershell invocation of:

iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

to try to install chocolatey to install node from there as System.Net.WebClient is not available in this image.

I guess my question is is there any container native way to get node.js installed internally without having to download something outside the container, copying it in, and then executing it. Kinda defeats the purpose of a multistage build if I have to do that or at least in my opinion makes it an ugly solution.

James Eby
  • 1,784
  • 20
  • 25

4 Answers4

1

instead curl use powershell's Invoke-WebRequest

instead unzip use Expand-Archive

installing MSI in nanoserver is not possible. For solution see: Powershell Silent Install in Nano Server with Docker

Miq
  • 3,931
  • 2
  • 18
  • 32
  • I will try and let you know, thanks for the quick response! – James Eby Jun 22 '18 at 14:10
  • Opened the container interactively with powershell and executed both methods just to test if this methods looks like it could work and they both execute, once I have the powershell commands setup to get node working I will post what I did and accept your answer. – James Eby Jun 22 '18 at 14:17
  • Just as an aside, it looks like the container image for Windows Server Version 1803 doesn't even have PowerShell installed in it, but I am told curl works natively so that can be used instead. – James Eby Jul 02 '18 at 17:05
1

Working off the answer from Miq I was able to create an initial Dockerfile which uses the 2.1 SDK image and pulls in node manually, here is what it looks like:

FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /app
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

ENV NODE_VERSION 8.11.3
ENV NODE_FULL_NAME node-v8.11.3-win-x64

#install node and npm as MS no longer does this in any .NET Core nanoserver based images since 2.1
RUN New-Item -ItemType directory -Path /build; \
    Invoke-WebRequest https://nodejs.org/dist/v${env:NODE_VERSION}/${env:NODE_FULL_NAME}.zip -OutFile /build/${env:NODE_FULL_NAME}.zip; \
    Expand-Archive -LiteralPath /build/${env:NODE_FULL_NAME}.zip /build; \
    $newPath = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).path; \
    $nodeFullName = ${env:NODE_FULL_NAME}; \
    $newPath = $newPath + ';/build/' + $nodeFullName; \
    Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $newPath;
James Eby
  • 1,784
  • 20
  • 25
0

They added Tar and Curl to the base runtimes.

FROM microsoft/dotnet:2.2-aspnetcore-runtime-nanoserver-1803 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

#Download the package we want and unzip it to our destination
RUN curl.exe -o node.zip https://nodejs.org/dist/v10.15.3/node-v10.15.3-win-x64.zip && \
  mkdir "C:\\Program Files\\node" && \
  tar.exe -xf node.zip -C "C:\\Program Files\\node" --strip-components=1
0

A different approach, using ADD and running as Administrator so I can set the PATH.

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-nanoserver-1903 as base
USER Administrator
WORKDIR /app
EXPOSE 80
EXPOSE 443
EXPOSE 1433
ADD https://nodejs.org/dist/v12.9.1/node-v12.9.1-win-x64.zip C:\\build\\node-v12.9.1-win-x64.zip
RUN mkdir "C:\\Program Files\\node" && \
  tar.exe -xf C:\\build\\node-v12.9.1-win-x64.zip -C "C:\\Program Files\\node" --strip-components=1
RUN setx /M PATH "C:\Program Files\node;%PATH%"
ben
  • 3,126
  • 3
  • 37
  • 51