diff --git a/xwiki-mysql-tomcat/Dockerfile b/xwiki-mysql-tomcat/Dockerfile
index 46b3e19c0dd24e4debed0819ac5b9578322a051d..5ee54dfbca477c137b74153e802f602b15a15613 100644
--- a/xwiki-mysql-tomcat/Dockerfile
+++ b/xwiki-mysql-tomcat/Dockerfile
@@ -32,19 +32,25 @@ ENV XWIKI_VERSION=8.4.4 \
 RUN echo "deb http://http.debian.net/debian jessie-backports main" > /etc/apt/sources.list.d/backports.list && \
   apt-get update && \
   apt-get -y upgrade && \
-  apt-get -y --force-yes install \
+  apt-get --no-install-recommends -y --force-yes install \
     curl \
     libreoffice \
     nano \
     openjdk-8-jdk \
     sudo \
     tomcat8 \
-    unzip
+    unzip && \
+  rm -rf /var/lib/apt/lists/*
 
 # Install XWiki as the ROOT webapp context in Tomcat
+# Create the Tomcat temporary directory
+# Configure the XWiki permanent directory
 RUN rm -rf /var/lib/tomcat8/webapps/* && \
+  mkdir -p /var/lib/tomcat8/temp && \
+  mkdir -p /var/lib/xwiki && \
   curl -L "http://download.forge.ow2.org/xwiki/xwiki-enterprise-web-${XWIKI_VERSION}.war" -o xwiki.war && \ 
   unzip -d /var/lib/tomcat8/webapps/ROOT xwiki.war && \
+  chown -R tomcat8:tomcat8 /var/lib/tomcat8 /var/lib/xwiki && \
   rm -f xwiki.war
 
 # Download the MySQL JDBC driver and install it in the XWiki webapp
@@ -58,24 +64,14 @@ RUN curl -L https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java
 # Configure Tomcat. For example set the memory for the Tomcat JVM since the default value is too small for XWiki
 COPY tomcat/setenv.sh /usr/share/tomcat8/bin/
 
-# Create the Tomcat temporary directory
-RUN mkdir -p /var/lib/tomcat8/temp
-
 # Setup the XWiki Hibernate configuration
 COPY xwiki/hibernate.cfg.xml /var/lib/tomcat8/webapps/ROOT/WEB-INF/hibernate.cfg.xml
 
-# Configure the XWiki permanent directory
-RUN mkdir -p /var/lib/xwiki
-
 # Set a specific distribution id in XWiki for this docker packaging.
 RUN sed "s/<id>org.xwiki.enterprise:xwiki-enterprise-web/<id>org.xwiki.enterprise:xwiki-enterprise-docker/" \
     < /var/lib/tomcat8/webapps/ROOT/META-INF/extension.xed > /var/lib/tomcat8/webapps/ROOT/META-INF/extension2.xed && \
   mv /var/lib/tomcat8/webapps/ROOT/META-INF/extension2.xed /var/lib/tomcat8/webapps/ROOT/META-INF/extension.xed
 
-# Set ownership and permission to the tomcat8 user
-RUN chown -R tomcat8:tomcat8 /var/lib/xwiki
-RUN chown -R tomcat8:tomcat8 /var/lib/tomcat8
-
 # Add scripts required to make changes to XWiki configuration files at execution time
 COPY xwiki/xwiki-config-replace.sh /usr/local/bin/xwiki-config-replace.sh
 COPY xwiki/xwiki-set-cfg /usr/local/bin/xwiki-set-cfg