BOUKANDOURA Mhamed
BOUKANDOURA Mhamed

Reputation: 1071

Unable to manipulate files and directories while building docker image

In Dockerfile i have this :

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"]

The error : unable to remove evry file and directory under /tmp/wildfly-10.1.0.Final

 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 : Before i was unable to run tar, the command return No such a file or directory until i switch to tmp folder, also sed command.

Upvotes: 2

Views: 798

Answers (1)

Robert
Robert

Reputation: 36833

In my machine I disn't have the problem you showed. I have this other:

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

I was able to fix it surrounding the rm with the proper users:

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

I've downloaded wildfly from here:

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

Then your Dockerfile becomes this:

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"]

It's working:

$ 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

You can try again discarding the previous chache: docker build . --no-cache

Upvotes: 1

Related Questions