mongo docker for testing; align mongodb directory naming

This commit is contained in:
negue
2025-11-27 22:52:10 +01:00
parent dcee86dc25
commit ff483a1081
3 changed files with 37 additions and 1 deletions

View File

@@ -15,7 +15,7 @@ services:
- "27017:27017"
restart: "unless-stopped"
volumes:
- "./mongodb-docker-data:/data/db"
- "./mongodb-data-docker:/data/db"
entrypoint: [ "/usr/bin/mongod", "--bind_ip_all", "--replSet", "rs" ]
mongoinit:
image: "mongo:7.0"

View File

@@ -0,0 +1,35 @@
# big thanks to https://pakisan.github.io/posts/docker-compose-mongodb-single-node-replica-set/ <3
networks:
mongodb-network:
name: "mongodb-network"
driver: bridge
services:
mongodb:
image: "mongo:7.0"
container_name: "mongodb"
networks:
- mongodb-network
hostname: "mongodb"
ports:
- "27017:27017"
restart: "unless-stopped"
volumes:
- "./mongodb-data-docker-testing:/data/db"
entrypoint: [ "/usr/bin/mongod", "--bind_ip_all", "--replSet", "rs" ]
mongoinit:
image: "mongo:7.0"
container_name: "mongodb_replSet_initializer"
restart: "on-failure" # WITHOUT THIS, the initializer tries only once and fails
depends_on:
- mongodb
networks:
- mongodb-network
command: >
bash -c "
until mongosh --host mongodb:27017 --eval 'db.adminCommand({ping:1})' >/dev/null 2>&1; do
sleep 1
done
mongosh --host mongodb:27017 --eval 'try { rs.initiate({_id: \"rs\", members:[{_id:0, host: \"mongodb:27017\"}]}); } catch(e) { print(\"rs.initiate skipped or failed: \" + e); }'
"

View File

@@ -108,6 +108,7 @@
"mongo:dev:rs": "run-rs -v 7.0.23 -l ubuntu2214 --keep --dbpath mongodb-data-rs --number 1 --quiet",
"mongo:test:rs": "run-rs -v 7.0.23 -l ubuntu2214 --keep --dbpath mongodb-data-rs-testing --number 1 --quiet",
"mongo:dev:docker": "docker compose -f docker-compose.mongo-local.yml up",
"mongo:test:docker": "docker compose -f docker-compose.mongo-test-local.yml up",
"mongo:test": "node scripts/start-local-mongo.mjs --test-db",
"postinstall": "git config --global url.\"https://\".insteadOf git:// && gulp build && cd website/client && npm install",
"apidoc": "gulp apidoc",