在Dockerfile中的docker生成错误
当我尝试运行“docker构build”。 或“docker构build – <Dockerfile”,错误如下所示:
[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
和我的Dockerfile是这样的:
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
任何人都可以有类似的经验,给我一个解决scheme。 非常感激!
尝试将基本映像更改为包含节点的映像,例如:
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
注意:只改变了第一行。
试试这个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
按照评论中的build议编辑
我想从这个修改 :
RUN sudo apt-get update RUN sudo -y apt-get install nodejs RUN sudo -y apt-get install npm
对此:
RUN sudo apt-get update && apt-get install -y nodejs npm
整体看起来像这样:
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
作为Dockerfiles的最佳实践 , 您需要在单一层中构build/安装软件包。
这将有助于图像形成使用最小的图层,这将减less图像的整体大小。
希望这可以帮助。
尝试这个:
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