This guide explains how to set up SSL certificates using Let's Encrypt for the Math2Visual Docker container using Docker Compose.
- Domain name pointing to your server
- Ports 80 and 443 open in your firewall
- Docker and Docker Compose installed
Edit nginx.conf and replace YOUR_DOMAIN with your actual domain name:
sed -i 's/YOUR_DOMAIN/your-domain.com/g' nginx.confOr manually edit the file and replace both occurrences of YOUR_DOMAIN.
mkdir -p certbot/conf certbot/wwwStart the container to allow certificate validation:
docker compose up -d appRun certbot to obtain your certificate:
sudo docker compose run --rm certbot-init \
certonly --webroot \
-w /var/www/certbot \
-d your-domain.com \
-d www.your-domain.com \
--email your-email@example.com \
--agree-tos \
--non-interactiveImportant: Replace:
your-domain.comwith your actual domainyour-email@example.comwith your email address
After the certificate is obtained, restart the container:
docker compose restart appThe renewal service automatically renews certificates before they expire:
docker compose up -d certbot-renewVisit your site: https://your-domain.com
Visit: https://www.ssllabs.com/ssltest/
docker compose exec certbot-renew certbot certificatesThe certbot-renew service automatically:
- Checks for certificates that need renewal every 12 hours
- Renews certificates 30 days before expiry
- Reloads Nginx after successful renewal
- Ensure
nginx.confhas the correct domain name - Verify certificate files exist:
ls -la certbot/conf/live/your-domain.com/ - Check file permissions
- Check certbot logs:
docker compose logs certbot-renew - Ensure port 80 is accessible for validation
- Verify webroot path is correct
- Test nginx config:
docker compose exec app nginx -t - Check logs:
docker compose logs app - Verify certificate paths in
nginx.conf
- Ensure your domain DNS points to your server
- Verify port 80 is accessible from the internet
- Check firewall rules
- Certificates are mounted read-only in the container
- Automatic renewal is configured
- Strong SSL protocols (TLS 1.2+) are enabled
- HSTS header is configured for security
- Keep certbot and nginx updated
If you need to manually renew:
docker compose run --rm certbot-renew certbot renew
docker compose exec app nginx -s reloaddocker compose exec certbot-renew certbot certificatesdocker compose logs certbot-renew