Article Image

It's a fairly common need to extract a certificate and key from traefik to use it for other reasons. In my case, I needed to grab a certificate for an existing domain and use it for my mail-server.

There's a bunch of very complex examples to dump all certificates, and semi-official traefik-cert-dumper.

My method only uses jq (jq) in a one-liner.

The Snippet

jq -r '.le.Certificates[] | select(.domain.main==\"''\") | .certificate' /data/acme.json | base64 -d > /out/tls_cert.pem

This should be fairly self-explanatory, but it extracts the certificate of and decodes the base64.

To extract the key, simply change the last jq expression .certificate to .key

As a scheduled docker service

version: "3.5"
    image: stedolan/jq
    # Dumps both certificate and key for ""
    entrypoint: |
      /bin/bash -c "
        jq -r '.le.Certificates[] | select(.domain.main==\"''\") | .certificate' /data/acme.json | base64 -d > /out/tls_cert.pem;
        jq -r '.le.Certificates[] | select(.domain.main==\"''\") | .key' /data/acme.json | base64 -d > /out/tls_key.pem;
      - common_letsencrypt:/data:ro # Mount traefik volume as read-only
      - out:/out # And whichever volume you want to output on
      mode: global
        constraints: [node.role==manager] # Only run on the manager node (Where traefik and its volume exists)
        delay: 24h # Re-run every 24 hours
        limits: { cpus: '0.1', memory: '32M' }
        reservations: { cpus: '0.025', memory: '16M' }
Blog Logo

Christopher LaPointe


Interested in Related Posts from this Site?

Virtual PDF Network Printer

May 04, 2023: For my [paperless-ngx]( install, I wanted to be able to easily "print" to it from...

Set up your own mailserver with Maddy

February 10, 2022: About a year ago I wanted to expand beyond namecheap's simple "email forwarding" service and...

Docker Samba / CIFS Volume (Photoview)

July 12, 2021: Recently I had a need to mount a CIFS volume as a docker volume: The...

Self-Hosted Analytics: Docker & Privacy-First

July 02, 2021: I have a lot of little sites. Probably too many. Includes various personal sites, sites...

Docker Swarm Registry and Auto Garbage Collection on NFS

March 15, 2021: After moving Traefik to v2, I also updated the common registry infrastructure. Namely, this stack...


Chris LaPointe

Another site of Code

Back to Overview