title: how to cache build env in docker-compose
body: <p>I am new to using <code>docker-compose</code> so I am not sure if I am using the correct approach to building changes in code. The docker-compose tutorial said that in order to update any changes in code, just make changes and refresh the link and the output will be refreshed(after code gets built by itself). That isn't happening for me. I have to stop the running docker-compose and then run the command <code>docker-compose up --build</code> which builds the system again. Now, my problem is that it downloads all the <code>requirements</code> in the python project. Currently the libraries aren't that many but they will increase at which point it will be extremely time consuming to download everything again and again. What should I do to avoid doing this when I only make changes to code and not the <code>requirements.txt</code> file.</p>
  
  <p>Here is an example of my setup:
  <br>docker-compose.yml</p>
  
  <pre><code>version: '2'
  services:
    web:
      build: .
      ports:
        - "5000:5000"
      env_file: .env
      depends_on:
        - db
      volumes:
        - ./webapp:/opt/webapp
  
    db:
      image: postgres:latest
      ports:
        - "5432:5432"
  
    redis:
      image: redis:alpine
      ports:
        - "6379:6379"
  </code></pre>
  
  <p>Dockerfile:</p>
  
  <pre><code>FROM python:3.4-alpine
  ADD . /code
  WORKDIR /code
  RUN pip install -r requirements.txt
  CMD ["python", "app.py"]
  </code></pre>
  
  <p>For every change I make in code and test it, I have to go through all these steps:</p>
  
  <pre><code>Building web
  Step 1/5 : FROM python:3.4-alpine
   ---&gt; 765c483d587c
  Step 2/5 : ADD . /code
   ---&gt; ce6f587fe477
  Removing intermediate container bceef7c06a89
  Step 3/5 : WORKDIR /code
   ---&gt; cd3f4951f718
  Removing intermediate container 5022780e47eb
  Step 4/5 : RUN pip install -r requirements.txt
   ---&gt; Running in 2dfe61c2537e
  Collecting flask (from -r requirements.txt (line 1))
    Downloading Flask-0.12-py2.py3-none-any.whl (82kB)
  Collecting redis (from -r requirements.txt (line 2))
    Downloading redis-2.10.5-py2.py3-none-any.whl (60kB)
  Collecting itsdangerous&gt;=0.21 (from flask-&gt;-r requirements.txt (line 1))
    Downloading itsdangerous-0.24.tar.gz (46kB)
  Collecting click&gt;=2.0 (from flask-&gt;-r requirements.txt (line 1))
    Downloading click-6.7-py2.py3-none-any.whl (71kB)
  Collecting Werkzeug&gt;=0.7 (from flask-&gt;-r requirements.txt (line 1))
    Downloading Werkzeug-0.11.15-py2.py3-none-any.whl (307kB)
  Collecting Jinja2&gt;=2.4 (from flask-&gt;-r requirements.txt (line 1))
    Downloading Jinja2-2.9.5-py2.py3-none-any.whl (340kB)
  Collecting MarkupSafe&gt;=0.23 (from Jinja2&gt;=2.4-&gt;flask-&gt;-r requirements.txt (line 1))
    Downloading MarkupSafe-0.23.tar.gz
  Installing collected packages: itsdangerous, click, Werkzeug, MarkupSafe, Jinja2, flask, redis
    Running setup.py install for itsdangerous: started
      Running setup.py install for itsdangerous: finished with status 'done'
    Running setup.py install for MarkupSafe: started
      Running setup.py install for MarkupSafe: finished with status 'done'
  Successfully installed Jinja2-2.9.5 MarkupSafe-0.23 Werkzeug-0.11.15 click-6.7 flask-0.12 itsdangerous-0.24 redis-2.10.5
   ---&gt; 6adce98b4bd0
  Removing intermediate container 2dfe61c2537e
  Step 5/5 : CMD python app.py
   ---&gt; Running in 554d0f0d4635
   ---&gt; c28028d2c0de
  Removing intermediate container 554d0f0d4635
  Successfully built c28028d2c0de
  Starting dockercompose_redis_1
  Starting dockercompose_db_1
  Recreating dockercompose_web_1
  Attaching to dockercompose_db_1, dockercompose_redis_1, dockercompose_web_1
  </code></pre>