我想在nodejs服务器上安装auditserver,所以我的auditserver用rpm。它作为手动步骤正常工作。
我写了一个如下的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
在构建docker文件时我看到了下面的问题。
root@CloudieBase:/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
root@CloudieBase:/tmp/sky-test#
可以帮助解决这个问题,使其成为完美的Dockerfile。谢谢。
答案 0 :(得分:0)
问题是您在执行/opt
命令时不在rpm
目录中(步骤7)。请参阅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