在构建docker镜像时无法操作文件和目录

时间:2017-07-09 13:15:00

标签: docker wildfly

在Dockerfile中我有这个:

FROM jboss/base-jdk:8

ENV WILDFLY_VERSION 10.1.0.Final
ENV JBOSS_HOME /opt/jboss/wildfly
ENV config $JBOSS_HOME/wildfly-10.1.0.Final/domain/configuration
ENV master_address 192.168.56.10
ENV tmp /tmp/wildfly-10.1.0.Final/domain/configuration

COPY wildfly-10.1.0.Final.tar.gz /tmp/wildfly-10.1.0.Final.tar.gz
RUN cd /tmp/
RUN tar xf /tmp/wildfly-10.1.0.Final.tar.gz -C /tmp/

RUN sed -i -e 's/noed_name/$HOSTNAME/g' $tmp/host.xml
RUN sed -i -e 's/host_master/$master_address/g' $tmp/host.xml
RUN sed -i -e 's/secret_value/$secret/g' $tmp/host.xml

RUN mv /tmp/wildfly-10.1.0.Final $JBOSS_HOME/
RUN rm /tmp/wildfly-10.1.0.Final.tar.gz

RUN secret=$(echo $HOSTNAME | base64 )

ENV LAUNCH_JBOSS_IN_BACKGROUND true

EXPOSE 8330
EXPOSE 9999

CMD ["/opt/jboss/wildfly/wildfly-10.1.0.Final/bin/domain.sh", "-b", "0.0.0.0", "-bmanagement", "0.0.0.0"]

错误:无法移除/tmp/wildfly-10.1.0.Final

下的evry文件和目录
 mv: cannot remove '/tmp/wildfly-10.1.0.Final/welcome-content/wildfly.css': No such file or directory
...
The command '/bin/sh -c mv /tmp/wildfly-10.1.0.Final $JBOSS_HOME/' returned a non-zero code: 1

PS:在我无法运行tar之前,该命令返回No such a file or directory,直到我切换到tmp文件夹,同时sed命令。

1 个答案:

答案 0 :(得分:1)

在我的机器上,我发现你遇到的问题。我有这个:

Step 14/18 : RUN rm /tmp/wildfly-10.1.0.Final.tar.gz
 ---> Running in c4a839a8bf8b
rm: cannot remove '/tmp/wildfly-10.1.0.Final.tar.gz': Operation not permitted

我能够使用适当的用户围绕rm进行修复:

...
USER root
RUN rm /tmp/wildfly-10.1.0.Final.tar.gz
USER jboss
...

我从这里下载了wildfly:

http://download.jboss.org/wildfly/10.1.0.Final/wildfly-10.1.0.Final.tar.gz

然后您的Dockerfile变为:

FROM jboss/base-jdk:8

ENV WILDFLY_VERSION 10.1.0.Final
ENV JBOSS_HOME /opt/jboss/wildfly
ENV config $JBOSS_HOME/wildfly-10.1.0.Final/domain/configuration
ENV master_address 192.168.56.10
ENV tmp /tmp/wildfly-10.1.0.Final/domain/configuration

COPY wildfly-10.1.0.Final.tar.gz /tmp/wildfly-10.1.0.Final.tar.gz
RUN cd /tmp/
RUN tar xf /tmp/wildfly-10.1.0.Final.tar.gz -C /tmp/

RUN sed -i -e 's/noed_name/$HOSTNAME/g' $tmp/host.xml
RUN sed -i -e 's/host_master/$master_address/g' $tmp/host.xml
RUN sed -i -e 's/secret_value/$secret/g' $tmp/host.xml

RUN mv /tmp/wildfly-10.1.0.Final $JBOSS_HOME/

USER root
RUN rm /tmp/wildfly-10.1.0.Final.tar.gz
USER jboss

RUN secret=$(echo $HOSTNAME | base64 )

ENV LAUNCH_JBOSS_IN_BACKGROUND true

EXPOSE 8330
EXPOSE 9999

CMD ["/opt/jboss/wildfly/wildfly-10.1.0.Final/bin/domain.sh", "-b", "0.0.0.0", "-bmanagement", "0.0.0.0"]

它在工作:

$ docker build .
..
..
..
Step 21/21 : CMD /opt/jboss/wildfly/wildfly-10.1.0.Final/bin/domain.sh -b 0.0.0.0 -bmanagement 0.0.0.0
 ---> Running in 06a9043977bc
 ---> ab4b6a623f3f
Removing intermediate container 06a9043977bc
Successfully built ab4b6a623f3f

您可以再次尝试放弃之前的行李箱:docker build . --no-cache