title: Dockerfile build remove source code from final image
body: <p>I am new to Docker. I want to build a docker image by building a c++ library using make command. The way I am doing it in Dockerfile is that</p>
  
  <ul>
  <li>copy the source code from host</li>
  <li>install required packages</li>
  <li>run make</li>
  <li>copy the libraries (.so) into different folder inside the image</li>
  <li>delete the source code</li>
  </ul>
  
  <p>The Dockerfile code is written below.</p>
  
  <p>The problem I am facing is that even after deleting the source code the final image size is big.</p>
  
  <p>Since each line of Dockerfile creates a different layer, there is a way to download the source code using curl or wget and later delete the source code in the same layer. But I don't like the solution.</p>
  
  <pre><code>FROM alpine
  
  RUN apk update &amp;&amp; apk add &lt;required_packages&gt;
  
  COPY source_code /tmp/source_code
  
  RUN make -C /tmp/source_code &amp;&amp; \
          mkdir /libraries/
          cp /tmp/lib/* /libraries/
          rm -rf /tmp/*
  </code></pre>
  
  <p>I just want to minimize the final image size. Is it the right way I am doing this or is there any better way? Please help.</p>