2017-06-06 49 views
0

當我嘗試運行「碼頭構建」時。或 '泊塢窗構建 - < Dockerfile',錯誤出現如下:碼頭文件中的碼頭構建錯誤

[[email protected]_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<[email protected]> ---> 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 <[email protected]> 
WORKDIR /opt/app 
COPY . ./ 
RUN npm install 
COPY dist/ /opt/app/ 
CMD node ./index.js < test.json 

任何人都可以有着相似的經歷,給我一個解決方案。非常感激!

+0

該碼頭圖像可能沒有nodejs – MinusFour

+0

您需要在機器中安裝NPM。 – Baruch

+0

當我執行npm -v和node -v時,我可以在centos操作系統中看到版本信息。看起來docker映像中沒有npm,但是我應該怎麼做 –

回答

0

嘗試基本圖像改變爲one containing node,如:

FROM node:6 
MAINTAINER Ke Peng <[email protected]> 
WORKDIR /opt/app 
COPY . ./ 
RUN npm install 
COPY dist/ /opt/app/ 
CMD node ./index.js < test.json 

注意:僅更改第一行。

+0

這對我很好 –

0

嘗試此Dockerfile

FROM ubuntu:14.04 
MAINTAINER Ke Peng <[email protected]> 
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 

編輯成在意見提出

+0

不,不工作,infors像:103新安裝,0刪除和1未升級。 需要獲得49.8 MB的檔案。 完成此操作後,將使用155 MB的額外磁盤空間。 你想繼續嗎? [Y/n]中止。 命令'/ bin/sh -c sudo apt-get install npm'返回一個非零代碼:1 –

+1

您需要傳遞'-y'標誌,以便在沒有用戶輸入的情況下自動安裝軟件包。另外,將安裝命令組合在一起是一個好主意,因此它不會創建不必要的圖層。 –

+0

是的,通過在apt-get install nodejs中加入-y,可以安裝相關的環境。謝謝 –

0

嘗試這種情況:

FROM ubuntu:14.04 
MAINTAINER Ke Peng <[email protected]> 
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 
0

我想從這個修改:

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 <[email protected]> 
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 

作爲best practice Dockerfiles,您需要在單一層中構建/安裝軟件包。

這將幫助圖像形成使用最小的圖層,這將減少圖像的整體大小。

希望這會有所幫助。