Docker certbor autoreNEW cert cron job

Hi.
If You using a Portainer for deploy yours applications with nginx, apache and Let’s Encrypt SSL you will need to auto renew the certificates when they were ended.
I'm using that bash script and put it in the /etc/cron.weekly folder (using UBUNTU 22.03) 


#!/bin/bash

# Set PATH
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

# Run the certbot container to renew the certs
docker run --rm -v certbot-webroot-VOLUME:/var/www/certbot -v certbot-data-VOLUME:/etc/letsencrypt:rw certbot/certbot renew

# Restart container
docker restart container-WITH-WEB-SERVER

# Copy cert for Portainer
cat /var/lib/docker/volumes/certbot-data-VOLUME/_data/live/YOUR.DOMAIN.COM/fullchain.pem > /opt/portainer/certs/cert.pem
cat /var/lib/docker/volumes/certbot-data/_data/live/YOUR.DOMAIN.COM/privkey.pem > /opt/portainer/certs/key.pem

docker restart portainer

PS.
When You will put script to the /etc/cron.weekly  folder don't add an extension to the script only name. With an extension script doesn't work.


That's all.
Bye. 

Comments

Popular posts from this blog

Відновлення роботи роботи роутера Linksys WRT54G3G-ST після невдалого обновлення прошивки.

Debian 12 (Proxmox Mail Gateway) and starting mailCow mail service