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.
The following gist is made of 3 parts:
- a docker compose setup sith
- a setup shell script that manages the SSL certificates generation
- a nginx configuration supporting HTTPS
You will need to tweak the hardcoded values that point to my service