3

I am unable to get Flask to notice changes to my code and reload, making it super hard to program iteratively.

My system: I am using a PC with Windows 10 Home to run Docker Toolbox (regular docker does not work on Windows 10 Home).

My code:

DockerFile

FROM python:3.4-alpine
RUN  pip install flask-security flask-sqlalchemy
RUN pip install requests
ADD . app
WORKDIR /app
RUN pip install -r requirements.txt
ENTRYPOINT ["python3"]
CMD ["app/app.py"]

docker-compose.yml

version: '3'
services:
  web:
    build: .
    ports:
     - "5000:5000"
    volumes:
     - .:/code

app/app.py

from flask import Flask
# Create app
app = Flask(__name__)
app.config['DEBUG'] = True
app.config['SECRET_KEY'] = 'super-secret'
# Bcrypt is set as default SECURITY_PASSWORD_HASH, which requires a salt
app.config['SECURITY_PASSWORD_SALT'] = 'super-secret-random-salt'

@app.route("/")
def hello():
    return 'hello world'

if __name__ == "__main__":
    app.run(host='0.0.0.0', port=5000, debug=True)

(I've edited this a little bit to be concise, and not give away what I'm doing :) )

  1. Am I doing something wrong?
  2. If not, I ran into this old ticket for VirtualBox where the situation sounds eerily similar. (https://www.virtualbox.org/ticket/14920) If this is my issue, what is a good solution or workaround? (I'm not looking to buy a new machine or OS)
user7097722
  • 65
  • 1
  • 1
  • 5

1 Answers1

3

This part:

volumes:
 - .:/code

You are mapping the /code in your container to the current directory. But your workdir is set to /app.

ADD . app
WORKDIR /app

So you don't need to add the app.py file to your workdir in your container, you just need to map the volume from current directory in your host machine to the /app directory in your container.

So, you need to change:

volumes:
 - .:/code

to:

volumes:
 - .:/app

in your docker-compose.yml file.

And remove the below line in your Dockerfile file:

ADD . app
Duc Filan
  • 6,769
  • 3
  • 21
  • 26