What I want: dockerize a Node.js web app (I am on Windows)
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.
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" ]
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:
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.
Use any custom Windows-based Docker image with Node.JS already installed (the option proposed by Kush Grover)
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.