TLDR: Nope, this isn’t nice or clean. But just needed something quick to renew SSL certificates on all of my wordpress sites, since cronjobs don’t work in docker containers. So I re-used PUTTY.
By default, Docker containers don’t support cron, making it challenging to automate tasks like SSL certificate renewal. Here’s my quick hack using Task Scheduler on Windows, together with PuTTY’s command-line tool, plink.
Here’s a quick guide to help you set it up:
-
Install PuTTY and PuTTYgen: If you haven’t already, download and install PuTTY and PuTTYgen on your Windows machine.
-
Create an SSH Key Pair: Use PuTTYgen to generate an SSH key pair if you don’t have one already. Save the private key (.ppk) in a secure location.
-
Configure PuTTY Session: Open PuTTY and configure a new session for your Docker container. Save the session with a meaningful name.
-
Automate Certificate Renewal Script: Now, create a script that uses plink to execute the certificate renewal command inside your Docker container. Here’s an example script:
plink.exe -load "putty-sessionname" -l {loginname} -pw {password} "docker exec {docker-container-id} certbot renew"
Replace
"putty-sessionname"
,{loginname}
,{password}
, and{docker-container-id}
with your actual PuTTY session name, login credentials, and Docker container ID respectively. -
Set Up Task Scheduler: Open Task Scheduler on your Windows machine. Create a new task and configure it to run your script at your desired interval, e.g., once a month.
This got the job done within 10 minutes and without needing to spin up a seperate docker container for it.
Note: I should do it properly one day though.