Skip to content

Commit

Permalink
working mongo docker compose 🎉
Browse files Browse the repository at this point in the history
  • Loading branch information
negue committed Dec 3, 2024
1 parent 7e4bf86 commit 82445d2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
4 changes: 2 additions & 2 deletions config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"LOGGLY_TOKEN": "example-token",
"LOG_REQUESTS_EXCESSIVE_MODE": "false",
"MAINTENANCE_MODE": "false",
"NODE_DB_URI": "mongodb://localhost:27017/habitica-dev?replicaSet=rs&directConnection=true",
"TEST_DB_URI": "mongodb://localhost:27017/habitica-test?replicaSet=rs&directConnection=true",
"NODE_DB_URI": "mongodb://localhost:27017/habitica-dev?replicaSet=rs&directConnection=true&readPreference=secondary",
"TEST_DB_URI": "mongodb://localhost:27017/habitica-test?replicaSet=rs&directConnection=true&readPreference=secondary",
"MONGODB_POOL_SIZE": "10",
"MONGODB_SOCKET_TIMEOUT": "20000",
"NODE_ENV": "development",
Expand Down
46 changes: 34 additions & 12 deletions docker-compose.mongo-local.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,37 @@
# big thanks to https://pakisan.github.io/posts/docker-compose-mongodb-single-node-replica-set/ <3

version: "3.9"
networks:
mongodb-network:
name: "mongodb-network"
driver: bridge
services:
mongo:
image: mongo:7.0
restart: unless-stopped
command: ["--replSet", "rs", "--bind_ip_all", "--port", "27017"]
healthcheck:
test: echo "try { rs.status() } catch (err) { rs.initiate() }" | mongosh --port 27017 --quiet
interval: 10s
timeout: 30s
start_period: 0s
retries: 30
volumes:
- "./mongodb-data2:/data/db"
mongodb:
image: "mongo:7.0"
container_name: "mongodb"
networks:
- mongodb-network
hostname: "mongodb"
ports:
- "27017:27017"
restart: "unless-stopped"
volumes:
- "./mongodb-data:/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: >
mongosh --host mongodb:27017 --eval "rs.initiate({
_id: \"rs\",
members: [
{_id: 0, host: \"mongodb\"}
]
})"

0 comments on commit 82445d2

Please sign in to comment.