title: Mounting Maven Repository to Docker
body: <p>I am trying to build a Java application and make a package using docker. This builds needs a maven repository which I don't want to include in the image, since it's very large. I wanted to try using volumes and mount my local maven repository to the maven repository in the image. I used <code>apt-get install -y maven</code> in order to have maven available, but I can't find the directory <code>.m2</code> in the image <code>$HOME</code>. </p>
  
  <p>I used <code>ls -la $HOME</code>, <code>ls -la</code> and <code>ls -la /root</code> to find the maven home, but there is no <code>.m2</code> directory there.</p>
  
  <p><strong>EDIT 1:</strong></p>
  
  <p>I have these lines in <code>Dockerfile</code>: </p>
  
  <pre><code>FROM ubuntu
  MAINTAINER Zeinab Abbasimazar
  # Install and configure required packages
  RUN apt-get update; \
      apt-get install -y --no-install-recommends apt-utils; \
      apt-get install -y dialog; \
      apt-get install -y wget unzip curl maven; \
      mkdir $HOME/.m2/; \
      ls -la /usr/share/maven/conf/; \
      echo \
      "&lt;settings xmlns='http://maven.apache.org/SETTINGS/1.0.0\' \
      xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' \
      xsi:schemaLocation='http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd'&gt; \
          &lt;localRepository&gt;/root/.m2/repository&lt;/localRepository&gt; \
          &lt;interactiveMode&gt;true&lt;/interactiveMode&gt; \
          &lt;usePluginRegistry&gt;false&lt;/usePluginRegistry&gt; \
          &lt;offline&gt;false&lt;/offline&gt; \
      &lt;/settings&gt;" \
      &gt; /usr/share/maven/conf/settings.xml
  VOLUME ["/home/zeinab/.m2/", "/root/.m2/"]
  # Build
  RUN mvn  -X clean install -pl components -P profile
  </code></pre>
  
  <p>Which puts local repository configurations in image's maven configuration file, mounts my local maven repository to a directory in the image and finally performs the build. As I can see in the maven build log that it's using the local repository path I expected:</p>
  
  <pre><code>[DEBUG] Reading global settings from /usr/share/maven/conf/settings.xml
  [DEBUG] Reading user settings from /root/.m2/settings.xml
  [DEBUG] Using local repository at /root/.m2/repository
  </code></pre>
  
  <p>But still can't detect dependencies. </p>