I am trying to run a simple flask app in debug mode using docker-compose. I have created my Dockerfile as follows:
FROM jazzdd/alpine-flask
EXPOSE 80
My docker-compose file looks like this:
version: '2'
networks:
test_network:
driver: bridge
services:
db:
networks:
- test_network
image: postgres:9.5.3
env_file:
- docker.env
expose:
- 5432
app:
networks:
- test_network
build: .
env_file:
- docker.env
expose:
- 80
ports:
- 80:80
volumes:
- ./app/:/app
command: -d
My docker.env just has password to postgres database. I created a simple python file as follows:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return "Hello, World"
if __name__ == '__main__':
app.run(debug=True,host='0.0.0.0')
Now to run the app, I am using docker-compose up -d --build
command. I would assume that after the app starts on the server, when I make any change to app.py file, it will be reflected on the webpage without me having to restart the containers. I'm not seeing the expected behavior. I tried setting my local env variable FLASK_DEBUG=1
but not sure if that would help. Am I missing something?
I also referenced this page but didn't see anything useful.
A sample (simplifed) runthru demostrating file edits with no need for container restarts outlined below for your reference.
app.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return "Hello, World"
if __name__ == '__main__':
app.run(debug=True,host='0.0.0.0',port=80)
You will need to specify the port for the flask development server in order to match the exposed container port of 80.
screenshot can be viewed here
Summary of Steps in screenshot (MAC OS X):
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With