enriched ACME documentation with Docker setup

Signed-off-by: Basil Bruhn <basil.bruhn@psi.ch>
This commit is contained in:
bruhn_b committed 2026-03-03 11:04:55 +01:00
1 parent d669f380e9
commit dfd2d9de4d
1 file changed
+80 -1
+80 -1
View File
@@ -1,7 +1,7 @@
# ACME - Automatic HTTPS Certificates
Until there is an puppet module to configure ACME via certbot, these are the steps needed to configure ACME (for nginx).
Configuration with docker is down below.
1. Install certbot
2. Create a /etc/letsencrypt/cli.ini file
@@ -80,3 +80,82 @@ Keys managed by certbot will be saved in `/etc/letsencrypt/live`. Either configu
!!! note
Important! Always use fullchain.pem as some tools like curl testmight not have the necessary intermediate certificates!
## Configuration with Docker
There are several images that use certbot integrated into whatever service you are using. (nginx for example) These images are not always maintained by the official project therefore I'd not recommend using them unless you know what you are doing and trust the maintainer.
In this documentation the nginx container is called nginx, please be aware of that when copying the documentation!
To get your certificates inside a container you need to volume mount `/etc/letsencrypt/live` into your container, where you would expect your certificates to be. Be careful, the certificate and key are in the same folder!
Also you need to "manually" reload the webserver using the certificate, when "ordering" a certificate and when its renewed by certbot. Bellow are the steps needed. The code blocks assume that you configured the cli.ini file with puppet module files:files already.
```
nginx:
image: nginx:latest
container_name: nginx
restart: always
ports:
- "80:80"
- "443:443"
volumes:i
- /etc/letsencrypt/archive:/etc/letsencrypt/archive:ro
- /etc/letsencrypt/live:/etc/letsencrypt/live:ro
```
And point your virtual host configuration to the correct folder:
```
server {
listen 80;
server_name myhost.psi.ch;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name myhost.psi.ch;
ssl_certificate /etc/letsencrypt/live/myhost.psi.ch/cert.pem;
ssl_certificate_key /etc/letsencrypt/live/myhost.psi.ch/privkey.pem;
location / {
proxy_pass https://myapp:443;
}
}
```
Getting the certificate with reloading the nginx inside the container, create a file (mine is called get-cert.sh)
And execute ./get-cert.sh myhost.psi.ch
```
/root/get-cert.sh
mode: 0744
content: |
#!/bin/bash
set -e
# Check for domain argument
if [ -z "$1" ]; then
echo "Usage: $0 <domain>"
exit 1
fi
DOMAIN="$1"
# Run Certbot with certonly
certbot certonly \
-d "$DOMAIN" \
--config /etc/letsencrypt/cli.ini
# Reload Nginx in the Docker container
docker exec nginx nginx -s reload
```
And create the post renewal hook:
```
/etc/letsencrypt/renewal-hooks/post/nginx.sh:
mode: '0544'
content: |
#!/bin/bash
docker exec nginx nginx -s reload
```