
How to Set Up Free HTTPS on an Ubuntu Server with Caddy and Docker (Step-by-Step Guide)
Learn how to set up free HTTPS on Ubuntu using Caddy and Docker in minutes. A complete, up-to-date guide for fast and secure servers.
Introduction
If you work on web projects, you already know an SSL certificate is non-negotiable—it’s essential to protect your users’ data and build trust. Traditionally, configuring HTTPS required dealing with Let’s Encrypt, cron jobs, and complex configurations in Nginx or Apache.
Caddy makes this process incredibly simple with automatic HTTPS and certificate renewals out of the box. Combined with Docker, you can deploy it in a clean and reproducible way.
In this guide, I’ll show you step by step how to set up your domain with free HTTPS on an Ubuntu server using Caddy and Docker.
Prerequisites
Before you start, make sure you have:
-
Ubuntu 20.04 / 22.04
-
Docker and Docker Compose installed
-
A domain pointing to your server’s public IP (e.g., yourdomain.com)
-
Ports 80 and 443 open
If you haven’t installed Docker yet, you can do so with:
sudo apt update
sudo apt install docker.io docker-compose -y
Step 1: Create the project folder
Create a folder for your Caddy project:
mkdir -p ~/caddy-docker
cd ~/caddy-docker
Inside this folder, you will create:
-
Caddyfile: your domain and routing configuration
-
docker-compose.yml: the container definition
Step 2: Create the Caddyfile
Create a file named Caddyfile:
nano Caddyfile
Paste this content:
yourdomain.com {
reverse_proxy localhost:3000
}
- Replace yourdomain.com with your actual domain.
- If your app is running on another port, adjust localhost:3000 accordingly.
Step 3: Create the docker-compose.yml
In the same folder, create docker-compose.yml:
version: '3'
services:
caddy:
image: caddy:latest
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile
- caddy_data:/data
- caddy_config:/config
volumes:
caddy_data:
caddy_config:
This setup tells Caddy to:
-
Listen on HTTP and HTTPS ports.
-
Persist certificates and configuration.
Step 4: Start the container
Launch Caddy with Docker Compose:
sudo docker-compose up -d
Caddy will automatically download Let’s Encrypt certificates. You can monitor the logs with:
sudo docker-compose logs -f
If everything is working correctly, you will see something like:
Server listening on [::]:443
Certificate obtained successfully
Now, open https://yourdomain.com and verify that the certificate is valid.
Step 5: Common issues and fixes
Port 80 already in use
If another service (like Apache) is using port 80, stop it:
sudo systemctl stop apache2
sudo systemctl disable apache2
Domain not propagated
Wait a few hours for DNS to update fully.
Volume permissions
Make sure you run Docker with sudo or add your user to the docker group.
Conclusion
With Caddy and Docker, you now have a secure HTTPS server running in minutes, with zero hassle and automatic renewals.
If you found this guide helpful, share it with your fellow developers and subscribe to my newsletter for more practical tutorials.
Leave a Reply
Your email address will not be published. Required fields are marked *



Comments