Sign inSign up

lacalvom/flaskapp

By lacalvom

•Updated over 3 years ago

Python Flask Gunicorn Application Wrapper - To-Do

Image
0

341

lacalvom/flaskapp repository overview

⁠Flaskapp

Python Flask Gunicorn Application Wrapper - To-Do

For this container I have based myself on the official Python Alpine image on Docker hub.

This container will connect both to the backend network to be able to access the mongodb database, and to the frontend network where I will connect to the nginx server that will act as a reverse proxy and forward requests to this container.

First we'll create the container without starting it, then we'll create the frontend network, and connect to it, and start the container.

When creating the container, I pass the directory where I have the application code, the dependencies file in bind mount mode and a start script flaskapp-start.sh as start command, with the necessary tasks to install the dependencies and start the application.

I also make use of environment variables to pass it the database connection parameters and other values that configure its execution environment.

flaskapp:

docker create --name flaskapp \
-e APP_ENV="<environment>" \
-e APP_DEBUG="<true-or-false>" \
-e APP_PORT=<port-number> \
-e MONGODB_DATABASE=<database-name> \
-e MONGODB_USERNAME=<username> \
-e MONGODB_PASSWORD=<password> \
-e MONGODB_HOSTNAME=<database-hostname> \
-v ./app:/app \
--network backend \
python:3.6.8-alpine3.9 sh -c "/app/flaskapp-start.sh"

Before starting it, I create the network frontend and connect the container to it:

docker network create frontend
docker network connect frontend flaskapp

Then I start the container:

docker start flaskapp

We verify the startup of the application by looking at the container logs:

docker logs flaskapp

Notes

I have modified the application so that it sends its logs in json format to the gunicorm server and I have increased the log level to DEBUG, all the logs are sent to the standard output of the container.

I have modified the application so that it validates the environment variables that are passed to it and if they do not have any value, they are assigned default values

Tag summary

Content type

Image

Digest

sha256:a443d3bcc…

Size

138.7 MB

Last updated

over 3 years ago

docker pull lacalvom/flaskapp