When I try to run 'docker build .' or 'docker build - < Dockerfile', errors appeared as below:
[root@VM_60_90_centos dtask-ctrip-train-domestic]# docker build .
Sending build context to Docker daemon 38.98 MB
Step 1 : FROM ubuntu:14.04 ---> 132b7427a3b4
Step 2 : MAINTAINER Ke Peng<ke.peng@jingli365.com> ---> Using cache --->
db9529465f77
Step 3: WORKDIR /opt/app ---> Using cache ---> 3122f40a8e56
Step 4 :COPY . ./ ---> 4d67a5fbf128 Removing intermediate container
c2d83602f613
Step 5 : RUN npm install ---> Running in 67680232cbdf
/bin/sh: 1: npm: not found The command '/bin/sh -c npm install'
returned a non-zero code: 127
and my Dockerfile like this:
FROM ubuntu:14.04
MAINTAINER Ke Peng <ke.peng@jingli365.com>
WORKDIR /opt/app
COPY . ./
RUN npm install
COPY dist/ /opt/app/
CMD node ./index.js < test.json
Can anyone have similar experience and give me an solution. Very appreciated!
Try this Dockerfile
FROM ubuntu:14.04
MAINTAINER Ke Peng <ke.peng@jingli365.com>
RUN sudo apt-get update
RUN sudo -y apt-get install nodejs
RUN sudo -y apt-get install npm
WORKDIR /opt/app
COPY . ./
RUN npm install
COPY dist/ /opt/app/
CMD node ./index.js < test.json
Edited as suggested in comments
Try this:
FROM ubuntu:14.04
MAINTAINER Ke Peng <ke.peng@jingli365.com>
RUN sudo apt-get update && \
sudo apt-get install -y nodejs npm
WORKDIR /opt/app
COPY . ./
RUN npm install
COPY dist/ /opt/app/
CMD node ./index.js < test.json
Try changing the base image to one containing node , such as:
FROM node:6
MAINTAINER Ke Peng <ke.peng@jingli365.com>
WORKDIR /opt/app
COPY . ./
RUN npm install
COPY dist/ /opt/app/
CMD node ./index.js < test.json
Note: changed the first line only.
I would like to modify from this :
RUN sudo apt-get update
RUN sudo -y apt-get install nodejs
RUN sudo -y apt-get install npm
to this:
RUN sudo apt-get update && apt-get install -y nodejs npm
and as whole it looks like this:
FROM ubuntu:14.04
MAINTAINER Ke Peng <ke.peng@jingli365.com>
RUN sudo apt-get update && apt-get install -y nodejs npm
WORKDIR /opt/app
COPY . ./
RUN npm install
COPY dist/ /opt/app/
CMD node ./index.js < test.json
As a best practice for Dockerfiles, you need to build/install packages in a single layer.
This will help the Image to be formed using minimal layers which will reduce the overall size of the Image.
Hope this helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.