title: Docker multi-stage build for flask application
body: <p>I want to dockerize <code>flask</code> application which has lots of dependencies. My goal is to reduce the size of the final docker image.</p>
  
  <p>I tried multi-stage build but it is not reducing the size of final docker image.</p>
  
  <p>Below is my <code>Dockerfile</code></p>
  
  <pre><code>FROM python:3.6-slim-buster as base
  
  RUN apt-get update &amp;&amp; apt-get install --no-install-recommends --no-upgrade -y \
      libglib2.0-0 libxext6 libsm6 libxrender1 libfontconfig1 &amp;&amp; rm -rf /var/lib/apt/lists/*
  
  
  WORKDIR /wheels
  
  COPY requirements.txt /wheels
  
  RUN pip install -U pip \
     &amp;&amp; pip wheel -r requirements.txt
  
  
  
  FROM python:3.6-slim-buster
  
  COPY --from=base /wheels /wheels
  
  
  RUN pip install -U pip \
         &amp;&amp; pip install -r /wheels/requirements.txt \
                        -f /wheels \
         &amp;&amp; rm -rf /wheels \
         &amp;&amp; rm -rf /root/.cache/pip/* 
  
  ...
  </code></pre>
  
  <p>Last <code>pip install...</code> command is taking up <code>905MB</code>.</p>
  
  <p>How should I separate all the requirements from the final image and reduce the overall size of the final docker image?</p>