1
votes

My Dockerfile is as shown below:

From ubuntu:14.04

WORKDIR /app

#COPY package.json /app/package.json
COPY . /app
RUN npm install

EXPOSE 3000

CMD ["npm","start"]

Now, when I run command sudo docker -t my-app .. It gives me the following error:

Sending build context to Docker daemon 453.6 kB Sending build context to Docker daemon Step 0 : FROM ubuntu:14.04 ---> 37a9c4a8276c Step 1 : WORKDIR /app ---> Using cache ---> a83d4ef27948 Step 2 : COPY . /app ---> 1029f5d7d8a3 Removing intermediate container eb9e7ea7f7e6 Step 3 : RUN npm install ---> Running in 5d4f2c05d2d8 /bin/sh: 1: npm: not found INFO[0000] The command [/bin/sh -c npm install] returned a non-zero code: 127

Is there anything missing in my Dockerfile?

2

2 Answers

2
votes

This is expected. Your image doesn't have node installed, since the base image is ubuntu. You should use the node image as a base image.

From node

WORKDIR /app

#COPY package.json /app/package.json
COPY . /app
RUN npm install

EXPOSE 3000

CMD ["npm","start"]
1
votes

Your Dockerfile is building vanilla ubuntu FROM ubuntu:14.04 so if you want to use npm/node in your container you'll need to setup node yourself by adding RUN commands to install node, following the install instructions for ubuntu.

Instead of this, you probably want to simply use the official node image found at:

https://hub.docker.com/_/node/

FROM node

or use a specific version/distro like

FROM node:8.4.0-wheezy

(other tags/versions/distros are listed on the docker hub page)