An open API service indexing awesome lists of open source software.

https://github.com/tardo/docker-flask

Docker image to run flask applications using gunicorn
https://github.com/tardo/docker-flask

docker-image flask gunicorn npm poetry postcss rollup supervisord

Last synced: 2 months ago
JSON representation

Docker image to run flask applications using gunicorn

Awesome Lists containing this project

README

        

# DOCKER FLASK
---

This docker image is prepared to run Flask applications using gunicorn. In addition, this image provides poetry and npm with rollup and postcss.

#### Important notes

- This image is for Flask projects using poetry, gunicorn, supervisor and npm.
- This image doesn't come with gunicorn and supervisor installed, this must be provided by your poetry configuration.

#### Mount points of interest

| MOUNT POINT | DESCRIPTION |
|----------|---------|
| /usr/src/app | Here is where your flask application must be |
| /root/.cache | Here is where poetry stores the packages |
| /root/.npm | Here is where npm stores the packages |

#### About your flask configuration

Threaded mode is handled by gunicorn so you must disable `threaded` mode in the configuration of your flask application.

#### Customize poetry and npm project installation process

| ENV. VAR | DEFAULT | Example |
|----------|---------|---------|
| $POETRY_INSTALL_ARGS | Empty | --no-dev |
| $NPM_INSTALL_ARGS | Empty | --no-save --omit=dev |

#### Recommended env. variables

| ENV. VAR | DEFAULT | VALUES |
|----------|---------|--------|
| $FLASK_ENV | development | production, development, testing |
| $NODE_ENV | development | production, development, testing |
| $POETRY_NO_DEV | False | True, False |
| $GUNICORN_PID_FILE | /tmp/gunicorn.pid | --path-- |

#### SQLAchemy problems?

You must adjust how SQAlchemy handles the connection pool to work correctly with gunicorn.

The simplest method is to disable the connection pool. This means that they are not recycled and a new connection is always opened:
```python
from sqlalchemy.pool import NullPool

db = SQLAlchemy(None, engine_options={'poolclass': NullPool})
```

More info. here: https://docs.sqlalchemy.org/en/13/core/pooling.html#using-connection-pools-with-multiprocessing-or-os-fork

#### Execute Flask CLI commands

A safe way to do this is using the 'inv_poetry' script:
```bash
docker-compose run --rm --entrypoint="" inv_poetry
```
** Replace `` and ``

#### Restart gunicorn workers

```bash
docker-compose run --rm --entrypoint="" restart_workers
```
** Replace ``

#### Aditional Information

This image supports the expansion of secrets with the syntax.: `DOCKER-SECRET->secret_name`