This docker image is prepared to run Flask applications using gunicorn. In addition, this image provides poetry and npm with rollup and postcss.
- 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 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 |
Threaded mode is handled by gunicorn so you must disable threaded
mode in the configuration of your flask application.
ENV. VAR | DEFAULT | Example |
---|---|---|
$POETRY_INSTALL_ARGS | Empty | --no-dev |
$NPM_INSTALL_ARGS | Empty | --no-save --omit=dev |
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-- |
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:
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
A safe way to do this is using the 'inv_poetry' script:
docker-compose run --rm --entrypoint="" <FLASK_SERVICE_NAME> inv_poetry <COMMAND>
** Replace <FLASK_SERVICE_NAME>
and <COMMAND>
docker-compose run --rm --entrypoint="" <FLASK_SERVICE_NAME> restart_workers
** Replace <FLASK_SERVICE_NAME>
This image supports the expansion of secrets with the syntax.: DOCKER-SECRET->secret_name