项目作者: otwn

项目描述 :
Flask boilerplate based on cookiecutter-flask running on Docker with uWSGI& Nginx
高级语言: JavaScript
项目地址: git://github.com/otwn/flask-on-docker.git
创建时间: 2017-03-16T17:12:19Z
项目社区:https://github.com/otwn/flask-on-docker

开源协议:BSD 3-Clause "New" or "Revised" License

下载


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

Quickstart (http://localhost:5000)

  1. conda create -n py35env python=3.5
  2. source activate py35env
  3. git clone https://github.com/otwn/flask-on-docker
  4. cd flask-on-docker
  5. pip install -r requirements.txt
  6. bower install

Then run the following commands

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

localhost5000

Quickstart (http://localhost:8000)

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

  1. ./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.

  1. # MongoDB Connection
  2. from pymongo import MongoClient
  3. import json
  4. from bson import json_util
  5. from bson.json_util import dumps
  6. MONGODB_HOST = 'Your Host IP address'
  7. MONGODB_PORT = 27017
  8. def get_db():
  9. c = MongoClient(MONGODB_HOST, MONGODB_PORT)
  10. return c.yourdatabase
  1. Run Apache on Host and access the flask app on Docker by ProxyPass
  • Apache 2.4 proxy.conf
    ```
    ProxyPreserveHost On
    Require all granted

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.