title: Maven docker cache dependencies
body: <p>I'm trying to use docker to automate maven builds. The project I want to build takes nearly 20 minutes to download all the dependencies, so I tried to build a docker image that would cache these dependencies, but it doesn't seem to save it. My Dockerfile is</p>
  
  <pre><code>FROM maven:alpine
  RUN mkdir -p /usr/src/app
  WORKDIR /usr/src/app
  ADD pom.xml /usr/src/app
  RUN mvn dependency:go-offline
  </code></pre>
  
  <p>The image builds, and it does download everything. However, the resulting image is the same size as the base <code>maven:alpine</code> image, so it doesn't seem to have cached the dependencies in the image. When I try to use the image to <code>mvn compile</code> it goes through the full 20 minutes of redownloading everything.</p>
  
  <p>Is it possible to build a maven image that caches my dependencies so they don't have to download everytime I use the image to perform a build?</p>
  
  <p>I'm running the following commands:</p>
  
  <pre><code>docker build -t my-maven .
  
  docker run -it --rm --name my-maven-project -v "$PWD":/usr/src/mymaven -w /usr/src/mymaven my-maven mvn compile
  </code></pre>
  
  <p>My understanding is that whatever <code>RUN</code> does during the docker build process becomes part of the resulting image.</p>