title: Running Flask in Docker Using Volumes Causes Error on Reload
body: <p>I'm setting up my dev environment for a flask app in a docker container and during dev I want to be able to put Flask in development mode so that I can get live reloads when I change a file. I'm using volumes so that I can edit the files outside of docker. I am getting the desired behavior from Flask, on editing the flask test file it detects the file change, however, it appears to be attempting to serve trunkated files instead of the files as edited resulting in errors from the app.</p>
  
  <p>Dockerfile:</p>
  
  <pre><code>FROM python:3.8.1-alpine3.11
  RUN apk update &amp;&amp; apk upgrade &amp;&amp; apk add bash
  
  #Set ENV Variables
  ENV FLASK_APP hello.py
  
  #Add user.
  RUN adduser -D eskimotv
  USER eskimotv
  
  #Set Work directory
  WORKDIR /home/eskimotv
  
  #Install Dependencies
  COPY requirements requirements
  RUN python -m venv venv
  RUN venv/bin/pip install --upgrade pip
  RUN venv/bin/pip install -r requirements/docker.txt
  
  #Copy project files
  COPY frontend frontend
  COPY migrations migrations
  COPY boot.sh ./
  
  #Deploy Project
  EXPOSE 5000
  #ENTRYPOINT ["./boot.sh"]
  </code></pre>
  
  <p>Docker-compose.yml:</p>
  
  <pre><code>version: '3'
  services:
    frontend:
      image: bentsea/eskimotv-frontend:latest
      build:
        dockerfile: frontend.dockerfile
        context: .
      ports:
        - "8000:5000"
      env_file: .env
      volumes:
        - './boot.sh:/home/eskimotv/boot.sh'
        - './hello.py:/home/eskimotv/hello.py'
        - './frontend:/home/eskimotv/frontend'
      #entrypoint: ./boot.sh
      restart: always
  </code></pre>
  
  <p>Simple flask app, hello.py:</p>
  
  <pre><code>from flask import Flask
  app = Flask(__name__)
  
  @app.route('/')
  def index():
      return '&lt;h1&gt;Hello World!&lt;/h1&gt;&lt;p&gt; Please work!&lt;/p&gt;'
  
  @app.route('/user/&lt;name&gt;')
  def user(name):
      return '&lt;h1&gt;Hello, {}!&lt;/h1&gt;'.format(name)
  </code></pre>
  
  <p>Environtment variable FLASK_ENV is set to development. When starting up the app for the first time all my changes are displayed correctly:</p>
  
  <p><a href="https://i.stack.imgur.com/woPJ5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/woPJ5.png" alt="Working App Serving Correctly"></a></p>
  
  <p>If I make a very simple edit, such as changing line 10 of hello.py with a cosmetic change, such as the following:</p>
  
  <pre><code>return '&lt;h1&gt;Hello, {}, I made a small change to the text!&lt;/h1&gt;'.format(name)
  </code></pre>
  
  <p>Flask will appropriately reload:</p>
  
  <pre><code> * Detected change in '/home/eskimotv/hello.py', reloading
   * Restarting with stat
   * Debugger is active!
   * Debugger PIN: 234-654-899
  172.21.0.1 - - [31/Dec/2019 20:00:20] "GET /user/David HTTP/1.1" 200 -
   * Detected change in '/home/eskimotv/hello.py', reloading
   * Restarting with stat
   * Debugger is active!
   * Debugger PIN: 234-654-899
  </code></pre>
  
  <p>However, the page will begin to produce an error rather than correctly display the page:</p>
  
  <p><a href="https://i.stack.imgur.com/hV1oY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hV1oY.png" alt="Example of error generated after file reloads."></a></p>
  
  <p>Sometimes it's just an EOL error that indicates that the file is truncated, sometimes it indicates this null error. Either restarting the Flask server or undoing the edits made to the file resolves the issue and the app will function normally. Restarting the server every time I make an edit is the action I was wanting to avoid.</p>
  
  <p>Does anyone have any ideas what would cause the files in this volume configuration to load incorrectly and what I can do to resolve the issue to get the intended behavior of having the reload display the file as it is edited? </p>