/docker-nginx-gunicorn-flask-letsencrypt

Boilerplate code for setting up Nginx + Gunicorn + Flask + Letsencrypt SSL certs using docker-compose.

Primary LanguagePythonMIT LicenseMIT

docker-nginx-gunicorn-flask-letsencrypt

This repository contains necessary files and configs to build Nginx + Gunicorn + Flask with Letsencrypt using Docker and docker-compose.

Note: Tested on Ubuntu 16.04 and 18.04

Base Docker Images 📎


+---------------------------------------+
| service            | image  | version |
+====================|========|=========+
| Flask and Gunicorn | alpine | 3.7     |
+--------------------|--------|---------+
| Nginx              | nginx  | latest  |
+---------------------------------------+

Requirements ⚠️


Set-up & Installation ⚙️


1) Define applications details

In the .env file, enter your application details for the below variables.

SSL_EMAIL=myemail@myemail.com
NGX_DOMAIN=mysuperwebsite.com
FLASK_SESSION_KEY=super_secret_key
FLASK_ENV=development

*SSL_EMAIL: Email address for Letsencrypt SSL certificate
*NGX_DOMAIN: Domain name for Nginx config and Letsencrypt SSL certificate
*FLASK_SESSION_KEY: Secret Key for Flask Session. It can be whatever you want. ie. 6d8dg8f4-49f493bf9-h30f489h9n
*FLASK_ENV: Python application environment development / production.

2) SSL Certificates

We need to install the Letsencrypt client to get the SSL certicates.

$ make install-le-client

You might need to enter your sudo password as the command needs to run with admin privileges.
It installs the Letsencrypt client and get a certificate for the specified domain name and email address.
Wait for the installation and follow the different instructions.

Note: Free Letsencrypt cert are only available for 90 days. To renew the cert run

$ make renew-le-cert

Firing up ✅


Start application

$ sudo make dc-start

Your web app should be now accessible at your domain with SSL certificates 🎉
Alt text

Stop application

$ sudo make dc-stop