Skip to content
This repository has been archived by the owner on Oct 7, 2020. It is now read-only.
/ flask-on-docker Public archive

Flask boilerplate based on cookiecutter-flask running on Docker with uWSGI& Nginx

License

Notifications You must be signed in to change notification settings

otwn/flask-on-docker

Repository files navigation

A Flask template on Docker with uWSGI & Nginx

Using the following repo:

If you create a flask template with cookiecutter-flask, you basically need to copy five files and edit as you need.

  • Dockerfile
  • nginx.conf
  • uwsgi.ini
  • start_docker.py
  • init_docker.sh
conda create -n py35env python=3.5
source activate py35env
git clone https://github.com/otwn/flask-on-docker
cd flask-on-docker
pip install -r requirements.txt
bower install

Then run the following commands

export FLASK_APP=/path/to/autoapp.py
export FLASK_DEBUG=1
flask run

localhost5000

The same flask application will run on docker in port 8000.

./init_docker.sh

localhost8000

Configuration

  1. Access MongoDB on "host" machine from Docker.

Pymongo is installed and added pymongo settings on main/public/views.py. Change MONGODB_HOST. It should be your host machine's ip address.

# MongoDB Connection
from pymongo import MongoClient
import json
from bson import json_util
from bson.json_util import dumps

MONGODB_HOST = 'Your Host IP address'
MONGODB_PORT = 27017

def get_db():
    c = MongoClient(MONGODB_HOST, MONGODB_PORT)
    return c.yourdatabase
  1. Run Apache on Host and access the flask app on Docker by ProxyPass
  • Apache 2.4 proxy.conf
ProxyPreserveHost On
<Proxy *>
  Require all granted
</Proxy>

ProxyPass /flask/ http://localhost:8000/
ProxyPassReverse /flask/ http://localhost/flask/

We can show the Flask app on Docker via proxy.

localhost/flask

To change the subdirectory name, replace 'flask' by 'your_subdirectory' from the following files

  • proxy.conf
  • start_docker.py

Troubleshooting

  • 403 Forbidden - Check permission of a directory/file
  • 502 Bad Gateway - Check a file name. Even a difference jQuery/ and jquery/ on asset.py would show a 502 error.

About

Flask boilerplate based on cookiecutter-flask running on Docker with uWSGI& Nginx

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published