|
1 | 1 | ## Pre-Hooks and Post-Hooks
|
2 | 2 |
|
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)). |
4 | 4 |
|
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): |
7 | 13 | ```shell
|
8 | 14 | $ docker run --detach \
|
9 | 15 | --name nginx-proxy-acme \
|
10 | 16 | --volumes-from nginx-proxy \
|
11 | 17 | --volume /var/run/docker.sock:/var/run/docker.sock:ro \
|
12 | 18 | --volume acme:/etc/acme.sh \
|
13 | 19 | --env "DEFAULT_EMAIL=mail@yourdomain.tld" \
|
14 |
| - --env "ACME_PRE_HOOK=echo 'start'" |
| 20 | + --env "ACME_PRE_HOOK=echo 'start'" \ |
15 | 21 | nginxproxy/acme-companion
|
16 | 22 | ```
|
17 | 23 |
|
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): |
20 | 38 | ```shell
|
21 | 39 | $ docker run --detach \
|
22 | 40 | --name nginx-proxy-acme \
|
23 | 41 | --volumes-from nginx-proxy \
|
24 | 42 | --volume /var/run/docker.sock:/var/run/docker.sock:ro \
|
25 | 43 | --volume acme:/etc/acme.sh \
|
26 | 44 | --env "DEFAULT_EMAIL=mail@yourdomain.tld" \
|
27 |
| - --env "ACME_POST_HOOK=echo 'end'" |
| 45 | + --env "ACME_POST_HOOK=echo 'end'" \ |
28 | 46 | nginxproxy/acme-companion
|
29 | 47 | ```
|
30 | 48 |
|
| 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 | + |
31 | 59 | #### Verification:
|
32 | 60 | 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`.
|
33 | 61 | The variable `Le_PreHook` contains the Pre-Hook-Command base64 encoded.
|
34 | 62 | The variable `Le_PostHook` contains the Pre-Hook-Command base64 encoded.
|
35 | 63 |
|
36 | 64 | #### Limitations
|
37 | 65 | * 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**. |
39 | 66 |
|
40 | 67 | #### 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. |
42 | 70 | * Monitoring.
|
0 commit comments