Pre-hook script not found in PATH

Hello,
I’m using Certbot with Docker and have some problems with pre and post hooks. For example I want restart nginx container.

I’m using command below:

sudo docker run -it --rm --name certbot \
-v "/etc/letsencrypt:/etc/letsencrypt" \
-v "/var/lib/letsencrypt:/var/lib/letsencrypt" \
-v "/var/log/letsencrypt:/var/log/letsencrypt" \
-v "/var/run/docker.sock:/var/run/docker.sock" \
-v $(which docker):/usr/bin/docker \
-e AWS_ACCESS_KEY_ID="****" \
-e AWS_SECRET_ACCESS_KEY="****" \
certbot/dns-route53 certonly --dns-route53 --dry-run -d example.net -d www.example.net --pre-hook "/usr/bin/docker restart nginx"

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Found credentials in environment variables.
Plugins selected: Authenticator dns-route53, Installer None
Running pre-hook command: /usr/bin/docker restart nginx
pre-hook command "/usr/bin/docker restart nginx" returned error code 127
Error output from pre-hook command docker:
/bin/sh: /usr/bin/docker: not found

Obtaining a new certificate
Performing the following challenges:
dns-01 challenge for example.net
dns-01 challenge for www.example.net
Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
 - The dry run was successful.
ubuntu@ip-172-31-34-210:~$ 

Does anybody know if this achivable at all? I mean using hooks if you use Certbot with Docker.

1 Like

The issue is that the docker binary from your host system is not compatible with the libc/loader inside the Certbot container, which is based on Alpine/musl.

My suggestion would be to figure out some way to run apk add docker inside the container first (perhaps using --entrypoint or by creating your own Docker image based on the Certbot image).

As long as you continue to mount the socket from the host system, everything should still work.

1 Like

Cool. Many thanks for explanation!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.