Awesome
flask-docker-compose
About
Docker-Flask is about Flask project organization and running it in a docker-compose containers. Application has a basic user model with authentication(passwords hashing), database migrations, administration interface, celery asynchronous tasks, manage script, debug toolbar, bootstrap starter templates.
Application scheme
Including the followings
-
Docker and Docker-Compose for managing project
-
Flask application running on UWSGI with next extensions:
-
Celery asynchronous tasks application
-
Supervisor initialize system for managing python applications
-
PostgreSQL object-relational database
-
Nginx frontend web server for production mode
-
Redis key-value storage server
-
RabbitMQ AMPQ server(for production only)
Pre-Build
- install docker https://github.com/docker/docker
- install docker-compose https://docs.docker.com/compose/install
Usage
Pull images
docker-compose pull
Build an image
docker-compose build flaskapp
Start a cluster
To start applications with development environment:
docker-compose up -d
To start applications with production environment (first copy configuration file and edit it)
cp app/settings/prod.py.repl app/settings/prod.py
docker-compose --file docker-compose.prod.yml up -d
To initialize, create migration and upgrade your database:
docker exec -it dockerflask_flaskapp_1 bash -c "python manage.py create_db"
To run ipython debug flaskapp shell:
docker exec -it dockerflask_flaskapp_1 bash -c "python manage.py shell"
To create admin user:
docker exec -it dockerflask_flaskapp_1 bash -c "python manage.py create_user -a"
Migrations
To initialize migrations:
docker exec -it dockerflask_flaskapp_1 bash -c "python manage.py db init"
To create a migration:
docker exec -it dockerflask_flaskapp_1 bash -c "python manage.py db migrate"
To upgrade your database with migration:
docker exec -it dockerflask_flaskapp_1 bash -c "python manage.py db upgrade"
Stop and destroy a cluster
docker-compose stop && docker-compose rm -f
Logs and troubleshooting
To check standard logs:
docker-compose logs
Access the application containers shell:
docker exec -it dockerflask_flaskapp_1 bash
Running tests
docker exec -it dockerflask_flaskapp_1 bash -c "python manage.py runtests"