How to Renew a Certbot Certificate in Docker Without Losing It on Redeploy

Persist Certbot state in Docker, test renewal from the scheduled environment, and reload the server that actually terminates TLS.

FBFenwei BianAuthorNov 24, 2026
  • https
  • certbot
  • docker
  • guide

For Certbot in Docker, keep the certificate lineage, renewal configuration and account state outside the container. Then run renewal with the same challenge setup used to obtain the certificate. The proxy that serves HTTPS must be able to load the new files after Certbot finishes.

Persist the config tree, including archive targets

Certbot's default configuration directory is /etc/letsencrypt. Put the full directory on a persistent volume or an approved bind mount. In a standard Certbot setup, the current certificate paths in live refer to numbered files in archive. Mounting only the live directory into another container can leave those links pointing to files the container cannot see.

StateWho needs access
Certbot configuration, account data and renewal filesThe Certbot task. Keep the full tree private and back it up securely.
Active certificate, chain and matching private keyThe process that terminates TLS, with only the access it needs.
Challenge stateThe authenticator that will renew. Retain the same usable webroot, port arrangement or scoped credential.

One design is to mount the full Certbot tree only in the renewal task, then copy the required certificate files to a protected serving directory through a host-owned deploy step. Another is a suitably restricted shared read-only mount for a single proxy that already has permission to read the private key. Test permissions from the actual proxy process. Back up the key material only under your organization's encrypted backup and access rules.

Test the real scheduled job

Start with an existing Certbot-managed test certificate and an image known to contain the required plugin. For example, after setting CERTBOT_IMAGE to that approved image reference, run docker run --rm --mount type=volume,src=certbot-config,dst=/etc/letsencrypt "$CERTBOT_IMAGE" renew --dry-run with the same additional mounts, plugin and networking that the production schedule will use. For a webroot setup, the authenticator writes to a path the web server exposes for the challenge. For a DNS plugin, the container needs controlled access to the credential file configured for that lineage. A missing mount can let a manual run work while the scheduled task fails.

Certbot's renewal documentation describes when deploy hooks run. A dry run tests issuance against the test service. The deploy hook usually needs a separate test. Certbot's --run-deploy-hooks dry-run option runs applicable hooks with the current active certificate after successful testing, rather than installing the staging certificate.

Verify the served certificate after a real renewal

Schedule Certbot outside the transient container, such as through your host's normal job runner. Give your serving process a narrow, host-owned reload path. Mounting the Docker daemon socket solely to reload the proxy gives the renewal container much wider control than it needs.

After a successful renewal, compare the new certificate's validity or fingerprint with what clients receive from the public endpoint. If the files changed but the live endpoint did not, check the serving path and reload first. If the files in live are absent after redeployment, recover the existing persistent volume and investigate mount configuration before requesting more certificates.

Sources and further reading

About the author(s)

Software Developer & Writer • Namefi
FBAuthor

Fenwei Bian is a software developer in her thirties who spends her working hours in pull requests and her weekends with her hands in soil or sawdust. Years of open source on GitHub taught her that names are interfaces: a good one is clear, honest about what it does, and kind to whoever has to use it next.

She gardens because it rewards patience and punishes wishful thinking, and she does woodwork because a joint either fits or it doesn't. Both habits show up in how she writes about naming — measure twice, check the source, and don't sand over a rough spot and hope no one notices.

For Namefi she writes about how domain markets actually move, the practical trade-offs of tokenizing and flipping names, and picking a domain you'll still be glad you own in twenty years.

Related guides

Discuss this post

View the discussion on Namefi Discuss