Docker + Node.js + Windows

I was able to successfully deploy and run this by changing the Dockerfile as follows...

FROM mcr.microsoft.com/windows/servercore:1803 as installer

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

RUN Invoke-WebRequest -OutFile nodejs.zip -UseBasicParsing "https://nodejs.org/dist/v12.4.0/node-v12.4.0-win-x64.zip"; Expand-Archive nodejs.zip -DestinationPath C:\; Rename-Item "C:\\node-v12.4.0-win-x64" c:\nodejs

FROM mcr.microsoft.com/windows/nanoserver:1803

WORKDIR C:/nodejs
COPY --from=installer C:/nodejs/ .
RUN SETX PATH C:\nodejs
RUN npm config set registry https://registry.npmjs.org/

Got the same issue when building my Dockerfile on Windows 10 with node:8. I changed to custom node image here: https://hub.docker.com/r/stefanscherer/node-windows/

Or else If you prefer to use the official one, try switching to Linux containers.


I know the original question is pretty old but since I had similar issue last days and couldn't find good solution in single place I decided to share my experience in solving this.

So, let's assume you want to run Windows-based Docker container on Windows and use Node.JS inside.

Here are options you have:

  1. Switch to Linux-based Docker container which also can be run in Windows. First line of docker file might look like this one:

    FROM node:latest

Let's just assume that moving to Linux-based container isn't an option for you. There might be several reasons for this (for example, in my case I tried to deploy my Angular app in Linux-based Docker container to local Azure Service Fabric cluster on Windows 10 but it supports Windows-based images only).

In this case you have to move to Windows-based container and there are two more options.

  1. Use any custom Windows-based Docker image with Node.JS already installed (the option proposed by Kush Grover)

  2. Create your own Windows-based Docker image and install Node.JS inside. This last option is what I eventually came up with since I didn't want to rely on some non-official public custom image.

Here is an example of Windows-based Docker file with Node.JS installation:

FROM mcr.microsoft.com/windows/servercore:1803 as installer

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

RUN Invoke-WebRequest -OutFile nodejs.zip -UseBasicParsing "https://nodejs.org/dist/v12.4.0/node-v12.4.0-win-x64.zip"; `
Expand-Archive nodejs.zip -DestinationPath C:\; `
Rename-Item "C:\\node-v12.4.0-win-x64" c:\nodejs

FROM mcr.microsoft.com/windows/nanoserver:1803

WORKDIR C:\nodejs
COPY --from=installer C:\nodejs\ .
RUN SETX PATH C:\nodejs
RUN npm config set registry https://registry.npmjs.org/

WORKDIR /app

# install and cache app dependencies
COPY src/WebSpa/package.json /app/src/WebSpa/package.json

WORKDIR /app/src/WebSpa
RUN npm install
RUN npm install -g @angular/cli@latest

# add app
COPY . /app

# start app
CMD cd /app/src/WebSpa && ng serve --host 0.0.0.0

A short explanation to this file. I use Windows-based official image (FROM ...servercore:1803...) then download Node.JS binaries (RUN Invoke-WebRequest...) and add some required stuff to registry (RUN npm config set registry...). Later I use Node.JS NPM commands to install required packages for my Angular app (RUN npm install) and install Angular CLI (RUN npm install -g @angular/cli@latest) to be able to run Angular on the container (...ng serve...).

Note, that I download Node.JS of version 12.4.0 (latest stable available at the moment) and you might want to use different version.

I hope this was clear enough and somebody will find this useful.