You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A note to run MongoDB with TLS in Docker on Synology NAS.
Pre-setup
Ignore any step if you have already done.
Install Docker via DSM Packages
Do I need to explain?
Allow SSH connection
Go to Synology DSM > Control Panel > Terminal & SNMP > Terminal
Check Enable SSH service and modify port if desired.
Create Let's Encrypt certificate
Go to Synology DSM > Control Panel > Certificate
Click Add > Select Add a new certificate
Select Get a certificate from Let's Encrypt
Enter required information
Click Apply
Important directories
/volume1/docker/<container_name>: the real path of a container. The name of volume1 might have a different postfix number if you have multiple NAS volumes. You need to find it out by yourself.
/usr/syno/etc/certificate/_archive: where Synology stores certificates.
Use cat DEFAULT and cat INFO to find out which folder include the certificate you are going to use. In my case, the sub-folder name is RyVRRS.
Create shell script to bundle pem files
Go to your MongoDB container folder, /volume1/docker/mongo for example. If not exists yet, make one.
Create folder ssl and data inside mongo.
Create a file bundle-mongo-pem.sh in mongo.
Add following shell script into bundle-mongo-pem.sh and modify path as per your system.
#!/bin/bash# path to certificate files
KEY="/usr/syno/etc/certificate/_archive/RyVRRS/privkey.pem"
CERT="/usr/syno/etc/certificate/_archive/RyVRRS/fullchain.pem"# bundle pem files
cat $KEY$CERT> /volume1/docker/mongo/ssl/mongo.pem
# setup access permission
sudo chmod 600 /volume1/docker/mongo/ssl/mongo.pem
# change the owner# I'm not sure if the username of docker are the same for every machine.# Check the owner of folder `docker`, mine is `999`.
sudo chown 999 /volume1/docker/mongo/ssl/mongo.pem
Make shell executable chmod +x bundle-mongo-pem.sh
Execute shell ./bundle-mongo-pem.sh
This should create a bundled pem file in /volume1/docker/mongo/ssl.
Once the certificates get auto-renewed by Synology, you have to execute bundle-mongo-pem.sh again and restart mongo. For sure you can implement some automation process, or modify volumes and command in docker-compose.yaml to the original certificate folder to avoid manual renew.
As mentioned before, you probably could modify these two sections to point to where Synology stores cert pem to avoid manual renew. Check official doc for more details.