Custom docker image with automatic clustering. Beware!!: The service can only be initilize once. If you remove the containers, you have to delete all volumes associated with the service.
cp .env.example .env
Edit the .env
file. change the default username and password.
Mongo nodes need to share the same key to be able to authenticate each-other
echo "MONGODB_CLUSTER_KEY="$(openssl rand -base64 756 | sed -z 's/\n/\\n/g') >> .env
if the above failes to create the env variable in .env
file, you have to do it in multiple steps.
- Create key file:
openssl rand -base64 756 > mongo_cluster_key
- Edit Key:
vim ./mongo_cluster_key
replace all new-line with \n
- Step 3:
Create a variable in
.env
file and use the string fromStep 2
as it's value
MONGODB_CLUSTER_KEY=####-Single line encrypted key-####
docker compose up -d