Skip to content

Instantly share code, notes, and snippets.

@topahl
Last active May 2, 2020 11:04
Show Gist options
  • Save topahl/39ff592167435d6bc00cc3ff66f6161e to your computer and use it in GitHub Desktop.
Save topahl/39ff592167435d6bc00cc3ff66f6161e to your computer and use it in GitHub Desktop.
Docker Letsencrypt Cloudflare DNS

Docker Letsencrypt Cloudflare DNS challenge

This gist is an example on how to automate the Letsencrypt DNS challenge using cloudflare and docker. The docker image used in this gist is the official certbot/dns-cloudflare image.

Setup

  1. Install Docker and Docker Compose
  2. Update the cfcredentials.ini file and type in your email and api key
# Cloudflare API credentials used by Certbot
dns_cloudflare_email = <email>
dns_cloudflare_api_key = <apiKey>
  1. Enter your email and domain in the docker-compose-new.yaml file on line 9
command:  certonly --dns-cloudflare --dns-cloudflare-credentials /root/.ssh/cfini -d <domain> -m <email> -n -v --agree-tos
  1. Run docker compose and create a new certificate
docker-compose -f docker-compose-new.yaml up
  1. To kee the certificates current, plan a job to run
docker-compose -f docker-compose-renew.yaml up

##Result

After you have done the setup, you should have a volume with the name something link this: letsencrypt_certs You cann now attach this volume to an nginx container and use the certificates on your webserver

How to automate renewal

to be written

# Cloudflare API credentials used by Certbot
dns_cloudflare_email = <email>
dns_cloudflare_api_key = <apiKey>
version: "3"
services:
certbot:
image: certbot/dns-cloudflare
volumes:
- certs:/etc/letsencrypt
- lib:/var/lib/letsencrypt
- ./cfcredentials.ini:/root/.ssh/cfini
command: certonly --dns-cloudflare --dns-cloudflare-credentials /root/.ssh/cfini -d <domain> -m <email> -n -v --agree-tos
volumes:
certs:
driver: local
lib:
driver: local
version: "3"
services:
certbot:
image: certbot/dns-cloudflare
volumes:
- certs:/etc/letsencrypt
- lib:/var/lib/letsencrypt
- ./cfcredentials.ini:/root/.ssh/cfini
command: renew
volumes:
certs:
driver: local
lib:
driver: local
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment