Skip to content

Instantly share code, notes, and snippets.

@mdPlusPlus
Last active May 15, 2026 20:59
Show Gist options
  • Select an option

  • Save mdPlusPlus/d0cca6f2e5b158a30c7feb9337fc81d3 to your computer and use it in GitHub Desktop.

Select an option

Save mdPlusPlus/d0cca6f2e5b158a30c7feb9337fc81d3 to your computer and use it in GitHub Desktop.
Reload NGINX Docker container after certbot renewal on host
#!/bin/bash
# Path: /etc/letsencrypt/renewal-hooks/deploy/01-nginx-docker.sh
### ##
# Inspired by: https://solariz.de/posts/20/letsencrypt_auto_nginx_reload_on_renew_doing_it_ri/ #
### ##
set -euo pipefail
# set -x # Just for debugging
# Is docker running?
if $(systemctl is-active --quiet docker)
then
# Create temporary file for output
TMP=$(mktemp /tmp/docker-nginx-test-result.XXXXXXXXXX) || { echo "Failed to create temp file"; exit 1; }
# Test nginx confiuration
docker exec nginx /usr/sbin/nginx -t 1>>${TMP} 2>>${TMP}
if $(grep -q "test is successful" $TMP)
then
echo "NGINX config test successful, reloading..."
docker exec nginx /usr/sbin/nginx -s reload
else
echo "Error: NGINX config test is unsuccessful!"
fi
rm -f ${TMP}
else
echo "Docker is not running, therefore the NGINX container won't reload its config."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment