Reputation: 322
I am new to Docker. We have a node based REST service and I am trying to create a docker image so that I can easily deploy the service on build agents. I have CD to the folder where we have the package.json of the service and added below docker file. I am on Win 10 build 14xxxxx and using Docker windows container. Do I need to pull a node image and install it on nanoserver first ?
FROM microsoft/nanoserver
# Create app directory
RUN powershell New-Item -ItemType directory -Path \usr\src\app
WORKDIR \usr\src\app
# Install app dependencies
COPY package.json \usr\src\app
RUN npm install
# Bundle app source
COPY . \usr\src\app
EXPOSE 8080
CMD [ "npm", "start" ]
When I run
docker build -t mycompany/node-engine
I am getting below error
'npm' is not recognized as an internal or external command,
operable program or batch file.
Below is the full output
Sending build context to Docker daemon 24.67 MB
Step 1/8 : FROM microsoft/nanoserver
---> a943c29f0046
Step 2/8 : RUN powershell New-Item -ItemType directory -Path \usr\src\app
---> Using cache
---> f1df2109ddd6
Step 3/8 : WORKDIR \usr\src\app
---> Using cache
---> 66d552a76612
Step 4/8 : COPY package.json \usr\src\app
---> Using cache
---> fcf9663854c3
Step 5/8 : RUN npm install
---> Running in b47b47ad1439
'npm' is not recognized as an internal or external command,
operable program or batch file.
The command 'cmd /S /C npm install' returned a non-zero code: 1
Upvotes: 2
Views: 5220
Reputation: 91
It looks like you could take advantage of the new commands they added to the Nano image:
curl.exe and tar.exe (Thank you Unix)
FROM mcr.microsoft.com/windows/nanoserver:1809
#Download the package we want and unzip it to our destination
RUN curl.exe -o node.zip https://nodejs.org/dist/v9.2.0/node-v9.2.0-win-x64.zip && \
mkdir "C:\\Program Files\\node" && \
tar.exe -xf node.zip -C "C:\\Program Files\\node" --strip-components=1
#Add node to PATH
ENV PATH “C:\\Program Files\\node:%PATH%”
#Start Node
#CMD [ “node.exe” ]
Upvotes: 4
Reputation: 2743
I know I am late to the party here, but I came here looking for an answer to the same question.
A bit of research later and I found that there are a variety of third party node + server nano docker images that people have built.
For example, this looks like a nice clean one: https://github.com/a11smiles/docker-nano-nodejs/blob/master/Dockerfile
If you have issues with using somewhat random / unsupported docker images rather than official images (many commercial organisations do) you can at least look at the Dockerfile and learn how it was done (and maybe attribute the source :)
Upvotes: 1
Reputation: 141
There is an image for this purpose in docker hub and you just need to use this image which was built on top of nano server:
https://hub.docker.com/r/compulim/nanoserver-node/
Upvotes: -1