An Nginx Dockerfile and docker-compose setup that includes the python-certbot-nginx script which helps generating instant SSL certificates for the Nginx proxy.
docker-compose.ymlfile that composes the Nginx reverse proxy and all other custom Docker images./nginxdirectory that contains theDockerfileof Nginx with a built-in CertBot installation./letsencryptdirectory which acts as a volume for the Nginx image insidedocker-composeto maintain the certificate throughout redeployments
Make sure to include an nginx-volume for letsencrypt as shown in the docker-compose file to maintain the ssl-certificate after a redeployment, otherwise you may get rate-limited for a week for too many re-tries.
-
Add all your domains (including subdomains) that should have HTTPS to the
default-conffile. -
docker-compose up -d -
Run
docker-compose psto get the name of the running Nginx container & copy it -
Execute the Nginx docker container using bash:
docker exec -it [name_of_nginx_container] bash -
Run the python-certbot-nginx script including all domain names (including subdomains) that should have HTTPS:
certbot --nginx -d [domain1] -d [domain2]...And follow the given instructions. -
Press
Ctrl + dto exit bash -
Check if your SSL certificate works here and vist
https://[your_domain]
The Nginx Docker image can also be pulled and integrated to docker-compose directly from Dockerhub under the image name: max37/nginx-ssl:latest.
Note that this image exposes the ports 443 and 80 automatically as part of the Dockerfile setup.