• Stars
    star
    178
  • Rank 213,719 (Top 5 %)
  • Language
    Dockerfile
  • License
    MIT License
  • Created over 5 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Boilerplate code for setting up Nginx + Gunicorn + Flask + automated LetsEncrypt certificates (https) using docker-compose.

docker-nginx-gunicorn-flask-letsencrypt

Boilerplate code for setting up Nginx + Gunicorn + Flask + LetsEncrypt certificates using docker-compose.


This repository contains necessary files to build a web-app running with Nginx / Gunicorn / Flask / LetsEncrypt (Certbot) using Docker and docker-compose.

Note: Tested on Ubuntu 16.04, 18.04, 20.04

Docker

service image
flask & gunicorn python:3.8-alpine
nginx nginx:1.19-alpine

Requirements

dependency commands
docker commands for Debian / Ubuntu
docker-compose commands for Debian / Ubuntu
make sudo apt install make
a domain or sub-domain DNS A record needs to points to your server static IP
open ports 80 (http) and 443 (https)

Setting things up

1) Clone this repo on your server

sudo git clone https://github.com/smallwat3r/docker-nginx-gunicorn-flask-letsencrypt.git

Install docker, docker-compose and make (commands can be found above).

2) Add user to docker group

sudo usermod -aG docker $USER

Log out from the server and log back in for changes to apply.

3) Define your application details

Copy .env.example to .env and set up the environment variables.

# .env

# Email to get alerts from LetsEncrypt.
[email protected]

# Domain name or subdomain linked to your server's public IP.
DOMAIN=mydomain.com

# Folder where your flask app is located in the repo. In this example
# it's under ./src/
APP_FOLDER=src

# Application environment name
FLASK_ENV=development

# It can be the application entrypoint (wsgi if using ./src/wsgi.py)
# or the application package (as in this case) as the app's
# configs are under ./src/example_app/__init__.py
FLASK_APP=example_app

Good to know

If you're running your own application and not the example one from this repository you probably need to update or replace the src/Dockerfile to your needs (in terms of dependencies etc). It's also known that some Python projects can have a hard time running from Python's Alpine images, so you might want/need to switch to a more standard python:3.8 image.

Turning it on

Start application

sudo make dc-start

🎉 Your web-app should now be running online with HTTPS 🎉

All commands

% make help
Usage: make [TARGET ...]

help            Show this help menu
dc-stop         Stop docker (might need sudo)
dc-start        Start docker (might need sudo)
dc-start-local  Start docker for local dev (w/o nginx)

Auto checks are running weekly to update the certificates.

License

See LICENSE file.

Contact

Please report issues or questions here.

Buy me a coffee

More Repositories

1

shhh

Share sensitive info without leaving a trace in your chat logs or email accounts.
Python
370
star
2

synonym

CLI tool to find synonyms in 15 different languages.
Shell
115
star
3

tubestatus

London Tube live service status from the terminal.
Shell
36
star
4

droid-sans-mono-sw

Customised version of the Droid Sans Mono font.
33
star
5

vim-mono-sw

A simple grayscale vim color scheme with a little touch of red
Vim Script
9
star
6

jailed-sftp-users

Jailed SFTP user management scripts.
Shell
9
star
7

dotfiles

My dotfiles
Emacs Lisp
9
star
8

vim-efficient

Minimal grayscale monochrome-ish vim color scheme.
Vim Script
9
star
9

sketch

Draft files on the go from your terminal in your favourite text editor.
Shell
6
star
10

emacs-simplicity-theme

Minimalist dark theme for Emacs.
Emacs Lisp
6
star
11

shopify-webhook-receiver

Flask app to catch Shopify webhooks and trigger actions.
Python
5
star
12

untappd.el

Display your latest Untappd feed in Emacs 🍻
Emacs Lisp
4
star
13

vim-simplicity

Extremely minimal vim colorscheme.
Vim Script
4
star
14

tubestatus.el

London Tube live service status from Emacs.
Emacs Lisp
3
star
15

shopify-webhook-router

Boilerplate code to process Shopify webhooks with Flask and Celery
Python
3
star
16

github-antibot

Block Github users using bots to mass-follow me.
Python
3
star
17

shhh-cli

Golang CLI to interact with Shhh
Go
2
star
18

sweep-cat

A 30 keys keyboard based on the Ferris Sweep 2.2, featuring the purr-fect code reviewer.
2
star
19

pyavatar

Generate default user avatars from a given string input
Python
2
star
20

homebrew-scripts

Personal Homebrew tap 🚰
Ruby
1
star