title: Docker: In Dockerfile, copy files temporarily, but not for final image
body: <p>I have a Java service I'd like to package, and the only thing the final docker image needs is the JAR file and a config file.  However, I need to run my <code>gradle</code> command first to build the JAR, but I don't want all the things that <code>gradle</code> uses to be in the result docker image.</p>
  
  <p>Here's my current DockerFile:</p>
  
  <pre><code>RUN apt-get update &amp;&amp; apt-get install -y openjdk-7-jdk
  COPY . /
  RUN ./gradlew shadowJar
  CMD ["java", "-jar", "service/build/libs/service.jar", "server", "service/service.yml"]
  </code></pre>
  
  <p>You can see I have to <code>COPY</code> everything first so that I can run <code>./gradlew</code> (otherwise it says the command cannot be found).  But in the end, all I need is the <code>service.jar</code> and <code>service.yml</code> files.</p>
  
  <p>I'm probably missing something, but how I can make everything available during the <code>./gradlew</code> build step, but only have the result image include the <code>service.jar</code> and <code>service.yml</code>.</p>