Docker + Node.js + Windows
Asked Answered
A

5

22

What I want: dockerize a Node.js web app (I am on Windows)

Windows container

docker-compose up gets me this error:

Service 'webapp' failed to build: no matching manifest for windows/amd64 in the manifest list entries

As far as I understand that is because there is no Node.js image for windows, and a fix would be to switch to Linux container.

Not enough memory

When I try to switch to a linux container, Docker tells me that I don't have enough memory. Changing the amount of allocated memory through the settings does not fix it.

Edit: files

docker-compose

version: '3'

services:
  webapp:
    build: ./Front
    volumes:
      - ./Front:./dockerized
    ports:
     - 5001:8080

Dockerfile:

FROM node:alpine

RUN mkdir -p ../dockerized

WORKDIR ../dockerized

COPY package*.json ../dockerized

RUN npm install

COPY . ../dockerized

EXPOSE 8080
CMD [ "npm", "start" ]
Ayrshire answered 4/4, 2018 at 19:44 Comment(1)
Share you config for docker-compose so that someone could see what's wrong with it. Otherwise the question is too broad.Paynter
C
30

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.

Clarindaclarine answered 6/6, 2019 at 17:32 Comment(1)
I'm getting ERROR: The system cannot find registry path specified. on RUN SETX PATH C:\nodejs any ideas?Faradic
M
10

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/
Misogynist answered 18/2, 2020 at 17:13 Comment(1)
WARNING - I lost over a day to the fact the SETX trashes the previous path variable contents breaking RUN commands that appear later in the file. Use : RUN SETX PATH \"$Env:PATH;C:\nodejs\" /mElectroacoustics
C
4

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.

Circumsolar answered 18/9, 2018 at 13:56 Comment(0)
R
2

The response from Kush Grover is great, but this repo is outdated (latest version of node is 12.18.3 into stefanscherer/node-windows:latest).

I'm borrowing the another GREAT response above (from Witcher) and create the new images below:

  • henriqueholtz/node-win:16.15.1
  • henriqueholtz/node-win:14.19.0

See if I've create more tags/versions here

To try this new images you can simply execute:

docker run -d -t --name=node-win-16-15-1 henriqueholtz/node-win:16.15.1
docker exec -it node-win-16-15-1 cmd
node --version
npm --version
Revolutionist answered 11/6, 2022 at 10:18 Comment(3)
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewLarrikin
@Larrikin thanks for this warn, I really agree. I don't sure if in this moment the recommendation is to remove my answer and keep it to comment below later when I will have suficient reputation? Thanks again.Revolutionist
I'm a little puzzled. Maybe keep it for now and as soon as you are able to do so, make a comment (preferably to the witcher's message, asking if he would be willing to add a mention in his message ). Only mention clearly the existence of windows container images and let the details of usage (and maybe add the construction instruction too) for the overview tab of the repository (docker hub here).Larrikin
J
-1

install and cache app dependencies

COPY src/WebSpa/package.json /app/src/WebSpa/package.json

Getting Error on Copy CTC1014: COPY failed: file not found in build context or excluded by .dockerignore: stat C:\src\WebSpa\package.json: file does not exist

Jhvh answered 5/6, 2023 at 14:1 Comment(1)
This information might be useful as a comment on the question, but this is not an answer.Escalade

© 2022 - 2024 — McMap. All rights reserved.