This image comes in two varieties depending on what Python version you require.
2.7
,2
,latest
3.6
,3
docker run -d -v /path/to/project:/app -p 80:80 relvacode/flask-microservice
All dependencies will be installed on start-up and uWSGI will automatically reload the Python application after a change is detected (20 second interval).
Use this in your Dockerfile:
FROM relvacode/flask-microservice
When your image is built it will add the build context to /app
and install any apt and pip dependencies during build time.
This is the recommended method for production deployments.
- Ubuntu 18.04
- Python
- NGINX
- Proxy the Python application on
/api
- Serve static files from
/app/static
- Proxy the Python application on
- uWSGI
- Serves Python application in
/app/app/api.py
- Serves Python application in
- flask
- flask-restful
- uwsgi
- nginx
- python-pip
- python-setuptools
The home directory where applications are served is /app
.
Under this directory your application should have this folder structure
/app
app/
- This is where your Python code goesapi.py
- Your main flask application file
static/
- Your static content such as .html, .js, .css filesrequirements.apt
- apt requirements, separated by newlinerequirements.pip
- pip requirements, separated by newline
This sets what Python file/module in /app/app
to serve using uWSGI. Do not include the file extension.
Defaults to api
which equates to /app/app/api.py
This sets what variable inside UWSGI_ENTRYPOINT points to the the uWSGI (Flask) application.
Defaults to app
.
Change to this directory before loading the Python application.
Defaults to /app/app
.
To enable error logging of application errors to the container log you should add the PROPAGATE_EXCEPTIONS
parameter to the Flask configuration.
from flask import Flask
app = Flask(__name__)
app.config['PROPAGATE_EXCEPTIONS'] = True