This project is a Proof of Concept (POC) for a system that dynamically deploys and serves static websites using Docker, Traefik, and a simple FastAPI backend. It automatically provisions and renews SSL certificates for each new site using Let's Encrypt.
The architecture consists of three main services orchestrated by docker-compose:
- Traefik: Acts as a reverse proxy and load balancer. It routes external traffic to the appropriate service based on the requested hostname (e.g.,
my-site.your-domain.com). It also automatically handles SSL certificate generation via Let's Encrypt. - FastAPI (
apiservice): A simple Python API with one endpoint:/deploy/{name}. When you call this endpoint, it dynamically updates Traefik's configuration to create a new route forname.{YOUR_DOMAIN}.com, pointing it to thehtml-server. - Nginx (
html-serverservice): A basic web server that serves the static content found in the./htmldirectory. All dynamically created sites will serve content from this directory.
- Dynamic Routing: Deploy new sites with a single API call.
- Automatic HTTPS: Traefik automatically obtains and renews SSL certificates from Let's Encrypt for each site.
- Simple & Scalable: Based on a simple, containerized architecture.
- Docker and Docker Compose
- A registered domain name (e.g.,
your-domain.com) - A server with a public IP address
This is the most critical step. For Traefik to route requests and for Let's Encrypt to issue certificates, you must configure your domain's DNS records.
You need to create an A record pointing to your server's public IP address for:
- The deployment API:
deployer.{YOUR_DOMAIN} - Each website you intend to create, or a wildcard for all subdomains.
Recommended Approach (Wildcard):
Create a wildcard A record to cover all subdomains:
| Type | Name | Value (Your Server IP) |
|---|---|---|
| A | * |
123.45.67.89 |
This way, any subdomain (site1.your-domain.com, site2.your-domain.com, etc.) will point to your server, and you won't need to add new DNS records for each deployment.
- Clone the repository.
- Update Domain Name: Replace all instances of
{YOUR_DOMAIN}.comwith your actual domain name in the following files:docker-compose.ymltraefik/dynamic.yml
- Update Email: In
traefik/traefik.yml, changeyouremail@domain.comto your email address. Let's Encrypt uses this to notify you about certificate expirations.
Run the following command from the project's root directory:
docker-compose up -d --buildThis will build the API image, pull the Traefik and Nginx images, and start all services in the background.
To deploy a new website, make a POST request to the /deploy/{name} endpoint of the API. The {name} will become the subdomain for your new site.
For example, to create my-new-site.your-domain.com, run the following curl command:
curl -X POST https://deployer.your-domain.com/deploy/my-new-siteTraefik will detect the configuration change, create the new route, and automatically fetch an SSL certificate. Within a minute, you should be able to access https://my-new-site.your-domain.com in your browser, and it will serve the content from the ./html directory.