Snippets

Frederik Banke Let's Encrypt docker setup

Created by Frederik Banke last modified
FROM alpine:3.7

COPY ./run.sh /root/run.sh
COPY ./renew.sh /root/renew.sh

RUN chmod +x /root/run.sh
RUN chmod +x /root/renew.sh

ENV BACKUP_SCHEDULE="0 3 * * *"

RUN echo "http://dl-cdn.alpinelinux.org/alpine/latest-stable/community" >> /etc/apk/repositories 
RUN apk update
RUN apk add docker

WORKDIR /root
CMD ["/root/run.sh"]
1
2
3
4
5
6
7
8
9
version: "3.2"

services:
  letsencrypt:
    build: letsencrypt

    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /usr/bin/docker:/usr/bin/docker:ro
# Command to run periodically
docker run --rm \  
    --name letsencrypt \
    -v "/data/storage/letsencrypt/etc/:/etc/letsencrypt" \
    -v "/data/storage/letsencrypt/lib/:/var/lib/letsencrypt" \
    certbot/certbot:latest \
    renew --quiet --no-self-upgrade

# Reload Nginx
#docker kill -s HUP nginx
docker service update --force --update-parallelism 1 --update-delay 30s patch_loadbalancer
1
2
3
4
5
6
7
#!/bin/sh

echo "$BACKUP_SCHEDULE /root/renew.sh" > /root/crontab.tmp
crontab /root/crontab.tmp
rm -f /root/crontab.tmp

/usr/sbin/crond -f -d 0

Comments (0)