Situatie
What You’ll Build
-
A web application container (Python Flask example)
-
An Nginx reverse-proxy container
-
Automatic SSL using Let’s Encrypt
-
A single
docker-compose.ymlstack
Solutie
Part 1: Prepare Your Server
Step 1 — Install Docker & Docker Compose
Ubuntu example:
Step 2 — Create a Project Folder
Part 2: Create the Application Container
Step 1 — Make a Simple Flask App
app/app.py:
Step 2 — Add a Dockerfile
app/Dockerfile:
Part 3: Configure Nginx Reverse Proxy
Create Nginx Configuration
nginx/default.conf:
Part 4: Build Docker Compose Stack
docker-compose.yml
Part 5: Launch the Stack
Build and run:
Part 6: Enable HTTPS
Run Certbot:
Restart Nginx:
Security Hardening Tips
-
Enable auto-renewal for SSL using a cron job
-
Limit container privileges using
read_only: true -
Use fail2ban to protect SSH
-
Place Nginx behind Cloudflare if desired
Optional Add-Ons
-
Add a Postgres or Redis service
-
Implement load-balancing with Nginx upstream blocks
-
Add GitHub Actions CI/CD pipeline to rebuild images automatically.
Leave A Comment?