Skip to content

Commit b4ccbf1

Browse files
committed
docs: per-container Pre-Hooks and Post-Hooks
1 parent 16f7e19 commit b4ccbf1

File tree

2 files changed

+42
-9
lines changed

2 files changed

+42
-9
lines changed

docs/Hooks.md

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,70 @@
11
## Pre-Hooks and Post-Hooks
22

3-
The Pre- and Post-Hooks of [acme.sh](https://github.com/acmesh-official/acme.sh/) are available through the corresponding environment variables. This allows to trigger actions just before and after certificates are issued (see [acme.sh documentation](https://github.com/acmesh-official/acme.sh/wiki/Using-pre-hook-post-hook-renew-hook-reloadcmd))
3+
The Pre- and Post-Hooks of [acme.sh](https://github.com/acmesh-official/acme.sh/) are available through the corresponding environment variables. This allows to trigger actions just before and after certificates are issued (see [acme.sh documentation](https://github.com/acmesh-official/acme.sh/wiki/Using-pre-hook-post-hook-renew-hook-reloadcmd)).
44

5-
#### Pre-Hook
6-
This command will be run before certificates are issued. For example `echo 'start'`:
5+
If you set `ACME_PRE_HOOK` and/or `ACME_POST_HOOK` on the **acme-companion** container, **the actions for all certificates will be the same**. If you want specific actions to be run for specific certificates, set the `ACME_PRE_HOOK` / `ACME_POST_HOOK` environment variable(s) on the proxied container(s) instead. Default (on the **acme-companion** container) and per-container `ACME_PRE_HOOK` / `ACME_POST_HOOK` environment variables aren't combined : if both default and per-container variables are set for a given proxied container, the per-container variables will take precedence over the default.
6+
7+
If you want to run the same default hooks for most containers but not for some of them, you can set the `ACME_PRE_HOOK` / `ACME_POST_HOOK` environment variables to the Bash noop operator (ie, `ACME_PRE_HOOK=:`) on those containers.
8+
9+
#### Pre-Hook: `ACME_PRE_HOOK`
10+
This command will be run before certificates are issued.
11+
12+
For example `echo 'start'` on the **acme-companion** container (setting a default Pre-Hook):
713
```shell
814
$ docker run --detach \
915
--name nginx-proxy-acme \
1016
--volumes-from nginx-proxy \
1117
--volume /var/run/docker.sock:/var/run/docker.sock:ro \
1218
--volume acme:/etc/acme.sh \
1319
--env "DEFAULT_EMAIL=mail@yourdomain.tld" \
14-
--env "ACME_PRE_HOOK=echo 'start'"
20+
--env "ACME_PRE_HOOK=echo 'start'" \
1521
nginxproxy/acme-companion
1622
```
1723

18-
#### Post-Hook
19-
This command will be run after certificates are issued. For example `echo 'end'`:
24+
And on a proxied container (setting a per-container Pre-Hook):
25+
```shell
26+
$ docker run --detach \
27+
--name your-proxyed-app \
28+
--env "VIRTUAL_HOST=yourdomain.tld" \
29+
--env "LETSENCRYPT_HOST=yourdomain.tld" \
30+
--env "ACME_PRE_HOOK=echo 'start'" \
31+
nginx
32+
```
33+
34+
#### Post-Hook: `ACME_POST_HOOK`
35+
This command will be run after certificates are issued.
36+
37+
For example `echo 'end'` on the **acme-companion** container (setting a default Post-Hook):
2038
```shell
2139
$ docker run --detach \
2240
--name nginx-proxy-acme \
2341
--volumes-from nginx-proxy \
2442
--volume /var/run/docker.sock:/var/run/docker.sock:ro \
2543
--volume acme:/etc/acme.sh \
2644
--env "DEFAULT_EMAIL=mail@yourdomain.tld" \
27-
--env "ACME_POST_HOOK=echo 'end'"
45+
--env "ACME_POST_HOOK=echo 'end'" \
2846
nginxproxy/acme-companion
2947
```
3048

49+
And on a proxied container (setting a per-container Post-Hook):
50+
```shell
51+
$ docker run --detach \
52+
--name your-proxyed-app \
53+
--env "VIRTUAL_HOST=yourdomain.tld" \
54+
--env "LETSENCRYPT_HOST=yourdomain.tld" \
55+
--env "ACME_POST_HOOK=echo 'start'" \
56+
nginx
57+
```
58+
3159
#### Verification:
3260
If you want to check wether the hook-command is delivered properly to [acme.sh](https://github.com/acmesh-official/acme.sh/), you should check `/etc/acme.sh/[EMAILADDRESS]/[DOMAIN]/[DOMAIN].conf`.
3361
The variable `Le_PreHook` contains the Pre-Hook-Command base64 encoded.
3462
The variable `Le_PostHook` contains the Pre-Hook-Command base64 encoded.
3563

3664
#### Limitations
3765
* The commands that can be used in the hooks are limited to the commands available inside the **acme-companion** container. `curl` and `wget` are available, therefore it is possible to communicate with tools outside the container via HTTP, allowing for complex actions to be implemented outside or in other containers.
38-
* The hooks are general options, therefore **the actions for all certificates are the same**.
3966

4067
#### Use-cases
41-
* Change some firewall rules just for the issuing process of the certificates, so the ports 80 and/or 443 don't have to be publicly reachable at all time.
68+
* Changing some firewall rules just for the ACME authorization, so the ports 80 and/or 443 don't have to be publicly reachable at all time.
69+
* Certificate "post processing" / conversion to another format.
4270
* Monitoring.

docs/Let's-Encrypt-and-ACME.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ If the ACME CA provides multiple cert chain, you can use the `ACME_PREFERRED_CHA
7575

7676
The `LETSENCRYPT_RESTART_CONTAINER` environment variable, when set to `true` on an application container, will restart this container whenever the corresponding cert (`LETSENCRYPT_HOST`) is renewed. This is useful when certificates are directly used inside a container for other purposes than HTTPS (e.g. an FTPS server), to make sure those containers always use an up to date certificate.
7777

78+
#### Pre-Hook and Post-Hook
79+
80+
The `ACME_PRE_HOOK` and `ACME_POST_HOOK` let you use the [`acme.sh` Pre- and Post-Hooks feature](https://github.com/acmesh-official/acme.sh/wiki/Using-pre-hook-post-hook-renew-hook-reloadcmd) to run commands respectively before and after the container's certificate has been issued. For more information see [Pre- and Post-Hook](./Hooks.md)
81+
82+
7883
### global (set on acme-companion container)
7984

8085
#### Default contact address

0 commit comments

Comments
 (0)