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.yml
file that composes the Nginx reverse proxy and all other custom Docker images./nginx
directory that contains theDockerfile
of Nginx with a built-in CertBot installation./letsencrypt
directory which acts as a volume for the Nginx image insidedocker-compose
to 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-conf
file. -
docker-compose up -d
-
Run
docker-compose ps
to 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 + d
to 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.