A containerised HTTPS Flask API

A containerised HTTPS Flask API

August 15, 2019Code

Turnkey dockerised setup for an HTTPS Flask API with SSL certificates included

I was wrapping things up for my freelance clients before holidays, and I had to migrate a dockerized flask API to HTTPS.

I knew how to do it with nginx + python on the server, but I researched a reproducible way to do it with nginx + docker.

Then I started pulling the thread and first creating a docker-compsoe setup for nginx + the flask API. But then you still need to manage your SSL certificates “manually” on the server with certbot.

I ended up with something pretty cool that I can reuse from now on: a docker-compose setup with certbot + nginx + flask, all in one.

Reusable Solution

The following gist is made of 3 parts:

  1. a docker compose setup sith nginx, certbot and flask
  2. a setup shell script that manages the SSL certificates generation
  3. a nginx configuration supporting HTTPS

You will need to tweak the hardcoded values that point to my service startup-meter.louisguitton.com.

Nginx + HTTPS + Docker | GitHub Gist


  1. Nginx and Let’s Encrypt with Docker in Less Than 5 Minutes | by Philipp | Medium
  2. How to setup your website for that sweet, sweet HTTPS with Docker, Nginx, and letsencrypt