title: Docker – Compile maven project inside docker container & run it from there
body: <p>I have a project running Vue &amp; Spring Boot that I need to create a <code>docker-compose.yml</code> file to run <code>mvn clean install</code> to generate the <code>.jar</code>, and then build a "new" image from another Dockerfile with that said <code>.jar</code> inside the docker container. </p>
  
  <p>This is the Dockerfile that needs to be run once the <code>mvn clean install</code> is completed: </p>
  
  <pre><code>FROM java:8
  
  ENV WKHTML_VERSION 0.12.4
  
  # Builds the wkhtmltopdf download URL based on version numbers above
  ENV DOWNLOAD_URL "https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/${WKHTML_VERSION}/wkhtmltox-${WKHTML_VERSION}_linux-generic-amd64.tar.xz"
  
  RUN apt-get update &amp;&amp; \
      apt-get install -y --no-install-recommends wget &amp;&amp; \
      wget $DOWNLOAD_URL &amp;&amp; \
      tar vxf wkhtmltox-${WKHTML_VERSION}_linux-generic-amd64.tar.xz &amp;&amp; \
      cp wkhtmltox/bin/wk* /usr/local/bin/ &amp;&amp; \
      cp wkhtmltox/lib/* /usr/local/lib/ &amp;&amp; \
      rm wkhtmltox-${WKHTML_VERSION}_linux-generic-amd64.tar.xz
  
  # @see https://spring.io/guides/gs/spring-boot-docker/
  COPY   server/target/redo-server-0.0.1-SNAPSHOT.jar app.jar
  ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","app.jar"]
  </code></pre>
  
  <p>So the build steps need to be something like this: </p>
  
  <ul>
  <li>Install node + maven / pull those images  </li>
  <li>Install <code>postgresql</code> &amp; pull that image</li>
  <li>Run <code>mvn clean install</code> &amp; generate <code>.jar</code></li>
  <li>Build new image from abovementioned <code>Dockerfile</code> and run it</li>
  </ul>
  
  <p>I am new to <code>docker-compose</code> so I am having troubles setting this up in the correct execution order. </p>
  
  <p>The reason I need to do this is due to a problem with the production pipeline not having <code>node or npm</code>, which is needed to run the full maven application (<code>Vue.js</code> and <code>Spring Boot</code> app), which is why it needs to be compiled from inside the Docker container</p>
  
  <p>It would be greatly appreciated if anyone could point me in the right direction, let alone – is this possible to do? </p>