2016-12-22 73 views
1

我想在nodejs服務器上安裝auditserver,所以我的審計服務器用rpm。它作爲手動步驟工作正常。RPM的Dockerfile問題

我寫下如下的Dockerfile。

FROM centos:centos6 

# Enable EPEL for Node.js 
RUN rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm 

# Install Node.js and npm 
RUN yum install -y npm 

# ADD rpm into container 
ADD auditserver-1-1.x86_64.rpm /opt/ 

RUN mkdir -p /opt/auditserver 

RUN cd /opt 

RUN rpm -Uvh auditserver-1-1.x86_64.rpm 

# cd to auditserver 
RUN cd /opt/auditserver 

# Install app dependencies 
RUN npm install 
# start auditserver 
RUN node server 

EXPOSE 8080 

同時建立碼頭文件我看下面的問題。

[email protected]:/tmp/sky-test# docker build -t sky-test . 
Sending build context to Docker daemon 38.4 kB 
Step 1 : FROM centos:centos6 
---> 9c95139afb21 
Step 2 : RUN rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm 
---> Using cache 
---> fd5b1bb647fc 
Step 3 : RUN yum install -y npm 
---> Using cache 
---> b7c2908fc583 
Step 4 : ADD auditserver-1-1.x86_64.rpm /opt/ 
---> 26ace798f98c 
Removing intermediate container 5ea6221797f5 
Step 5 : RUN mkdir -p /opt/auditserver 
---> Running in 8f7292364245 
---> 9b340033f6b7 
Removing intermediate container 8f7292364245 
Step 6 : RUN cd /opt 
---> Running in c7d20fd251f3 
---> 0cdf90b6cb2e 
Removing intermediate container c7d20fd251f3 
Step 7 : RUN rpm -Uvh auditserver-1-1.x86_64.rpm 
---> Running in 4473241e5077 
error: open of auditserver-1-1.x86_64.rpm failed: No such file or directory 
The command '/bin/sh -c rpm -Uvh auditserver-1-1.x86_64.rpm' returned a non-zero code: 1 
[email protected]:/tmp/sky-test# 

可以幫助完成Dockerfile。謝謝。

回答

0

問題是在執行rpm命令(步驟7)時,您不在/opt目錄中。查看this answer,瞭解它發生的原因。報價:

每次你跑,你產卵一個新的容器,因此pwd是'/'。

有關如何解決該問題,請參見this question。總結:你可以使用WORKDIR dockerfile命令或更改此部分:

RUN cd /opt 
RUN rpm -Uvh auditserver-1-1.x86_64.rpm 

這樣:

RUN cd /opt && rpm -Uvh auditserver-1-1.x86_64.rpm