-
-
Save gauraputu/2de155007a739d42a114754c90b9323d to your computer and use it in GitHub Desktop.
Alpine Nginx with auto renew letsencrypt certbot Dockerfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM nginx:alpine | |
EXPOSE 80 443 | |
VOLUME ["/etc/nginx/conf.d/", "/var/www/html", "/etc/letsencrypt"] | |
RUN apk add --no-cache certbot \ | |
&& echo "0 0,12 * * * python -c 'import random; import time; time.sleep(random.random() * 3600)' && certbot renew --post-hook \"nginx -s reload\"" > /etc/crontabs/root | |
CMD ["/bin/sh", "-c", "crond -b && certbot renew && nginx -g 'daemon off;'"] | |
# To create a letsencrypt cert, you need login the container, | |
# and execute the following command (don't forget config the nginx root folder, for here is /var/www/html): | |
# certbot certonly --webroot -w /var/www/html -d example.com -m [email protected] --agree-tos --noninteractive | |
# This docker image will try to renew all certs every 12h. | |
# Certs should be at /etc/letsencrypt/live/example.com/fullchain.pem and /etc/letsencrypt/live/example.com/key.pem respectively. | |
# You need set the nginx config to enable certs manually. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment