Dockerfile – RUN rm not working! ex: ‘RUN rm -rf /usr/local/tomcat/webapps/ROOT’

Dockerfile – RUN rm not working! – I was going completely bananas trying to find out why a simple Dockerfile command wasn’t working.

Here is my example Dockerfile:

FROM tomcat:9
LABEL maintainer "reuben_xxx@xxx.edu"
COPY tomcat-users.xml /usr/local/tomcat/conf/
COPY server.xml /usr/local/tomcat/conf/
COPY web.xml /usr/local/tomcat/conf/
COPY context.xml /usr/local/tomcat/webapps/manager/META-INF
COPY ROOT.war /usr/local/tomcat/webapps/
RUN rm -rf /usr/local/tomcat/webapps/ROOT
RUN rm -rf /usr/local/tomcat/webapps/docs
RUN rm -rf /usr/local/tomcat/webapps/examples

These last three lines, were failing during the build, as shown here:

$ docker build -t app_name .

Sending build context to Docker daemon 52.55MB
Step 1/10 : FROM tomcat:9
9: Pulling from library/tomcat
9f0706ba7422: Pull complete
d3942a742d22: Pull complete

Step 7/10 : COPY ROOT.war /usr/local/tomcat/webapps/
---> 485815d97f89
Removing intermediate container 5ef00497c970
Step 8/10 : RUN rm -rf /usr/local/tomcat/webapps/ROOT
---> Running in 61594cd2432e
rm: cannot remove ‘/usr/local/tomcat/webapps/ROOT/WEB-INF’: Directory not empty
The command '/bin/sh -c rm -rf /usr/local/tomcat/webapps/ROOT' returned a non-zero code: 1

After some heavy google digging, which turned up a false report that this was a docker bug, I found the answer by typing docker info on the command line. Notice the warning message at the bottom of the output.

$ docker info
Containers: 1
Running: 0
Paused: 0
Stopped: 1
Images: 7
Server Version: 17.05.0-ce
...
WARNING: overlay: the backing xfs filesystem is formatted without d_type support, which leads to incorrect behavior.
Reformat the filesystem with ftype=1 to enable d_type support.
Running without d_type support will not be supported in future releases.

I ran the same Dockerfile build on a system where the file system supported d_type and the Dockerfile build worked fine. The rm (remove) command worked without error.

Before getting too deep into docker, you should ensure your filesystem supports d_type – use OverlayFS storage driver.

The file system should be formatted with ftype=1 or d_type=true. Docker will not support running without d_type support in future releases.

Feel the breeze!
Reuben

Leave a Reply

Your email address will not be published. Required fields are marked *