title: Docker : Install Maven dependencies during build stage only?
body: <p>Still new to Docker and trying to get a Jetty webservice to run inside a container. 
  This is my docker file at the moment</p>
  
  <p><strong>Recipe</strong></p>
  
  <pre><code>FROM maven:3.3-jdk-8-alpine
  
  # Install packages
  # To find packages to install see - https://pkgs.alpinelinux.org/packages
  RUN apk add --no-cache curl tar bash wget apache-ant
  RUN apk info
  
  # Do any Maven configuration
  ENV MAVEN_HOME /usr/share/maven
  VOLUME "$USER_HOME_DIR/.m2"
  ENV MAVEN_CONFIG "$USER_HOME_DIR/.m2"
  
  
  # Copy over project source files to the /tmp folder
  COPY . /tmp/project
  WORKDIR /tmp/project
  
  # Preinstall any Maven depencencies
  RUN mvn install -pl '!deb' -DskipTests
  
  # Default command when running the docker image, can be overriden
  CMD cd webapp/ &amp;&amp; mvn jetty:run
  </code></pre>
  
  <p>During the docker build I specify <code>maven install</code> to install all dependencies for the project and build the jars for each module from sources.</p>
  
  <p>However when then run the docker container, it still tries to reinstall all the dependencies and then fails because it cannot find my api.jar file</p>
  
  <p>My project structure is like so</p>
  
  <p><strong>Project structure</strong>
  service</p>
  
  <ul>
  <li>api </li>
  <li>lib</li>
  <li>webapp</li>
  <li>pom.xml</li>
  </ul>
  
  <p><strong>Error</strong></p>
  
  <blockquote>
    <p>The following artifacts could not be resolved:
    com.foo.service:service-api:jar:1.14-SNAPSHOT</p>
  </blockquote>
  
  <p>Doing the same steps outside of a container works fine and the jetty service starts ok. Any ideas how to fix?</p>