title: How to avoid reinstalling packages when building Docker image for Python projects?
body: <p>My Dockerfile is something like</p>
  <pre><code>FROM my/base
  
  ADD . /srv
  RUN pip install -r requirements.txt
  RUN python setup.py install
  
  ENTRYPOINT [&quot;run_server&quot;]
  </code></pre>
  <p>Every time I build a new image, dependencies have to be reinstalled, which could be very slow in my region.</p>
  <p>One way I think of to <code>cache</code> packages that have been installed is to override the <code>my/base</code> image with newer images like this:</p>
  <pre><code>docker build -t new_image_1 .
  docker tag new_image_1 my/base
  </code></pre>
  <p>So next time I build with this Dockerfile, my/base already has some packages installed.</p>
  <p>But this solution has two problems:</p>
  <ol>
  <li>It is not always possible to override a base image</li>
  <li>The base image grow bigger and bigger as newer images are layered on it</li>
  </ol>
  <p>So what better solution could I use to solve this problem?</p>
  <h2>EDIT:</h2>
  <p>Some information about the docker on my machine:</p>
  <pre><code>☁  test  docker version
  Client version: 1.1.2
  Client API version: 1.13
  Go version (client): go1.2.1
  Git commit (client): d84a070
  Server version: 1.1.2
  Server API version: 1.13
  Go version (server): go1.2.1
  Git commit (server): d84a070
  ☁  test  docker info
  Containers: 0
  Images: 56
  Storage Driver: aufs
   Root Dir: /var/lib/docker/aufs
   Dirs: 56
  Execution Driver: native-0.2
  Kernel Version: 3.13.0-29-generic
  WARNING: No swap limit support
  </code></pre>