Docker Let's Encrypt and certbot

Hi!

I am trying to setup SSL for my Home Assistant in Docker. Are the following two commands correct for setting up SSL and auto renewal?

sudo mkdir /etc/letsencrypt /var/lib/letsencrypt
sudo docker run -it --rm -p 80:80 --name certbot \
                -v "/etc/letsencrypt:/etc/letsencrypt" \
                -v "/var/lib/letsencrypt:/var/lib/letsencrypt" \
                quay.io/letsencrypt/letsencrypt:latest certonly \
                --standalone --standalone-supported-challenges http-01 \
                --email [email protected] -d sub.domain.com

sudo 0 0 * * * docker run -it --rm -p 80:80 --name certbot \
                -v "/etc/letsencrypt:/etc/letsencrypt" \
                -v "/var/lib/letsencrypt:/var/lib/letsencrypt" \
                quay.io/letsencrypt/letsencrypt:latest renew >> /var/log/certbot.log 2>&1

To answer my own question. Yes above works, remember to setup the volume in the docker container of home assistant:

/etc/letsencrypt/live/domain/fullchain.pem
/etc/letsencrypt/live/domain/privkey.pem

@MvdB, thanks for this. I just set this up myself, and wanted to mention that the quay.io/letsencrypt/letsencrypt image has been replaced with certbot/certbot on Docker Hub. Otherwise, everything is still the same.

4 Likes