Skip to content

Commit 82445d2

Browse files
committed
working mongo docker compose 🎉
1 parent 7e4bf86 commit 82445d2

File tree

2 files changed

+36
-14
lines changed

2 files changed

+36
-14
lines changed

config.json.example

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
"LOGGLY_TOKEN": "example-token",
3535
"LOG_REQUESTS_EXCESSIVE_MODE": "false",
3636
"MAINTENANCE_MODE": "false",
37-
"NODE_DB_URI": "mongodb://localhost:27017/habitica-dev?replicaSet=rs&directConnection=true",
38-
"TEST_DB_URI": "mongodb://localhost:27017/habitica-test?replicaSet=rs&directConnection=true",
37+
"NODE_DB_URI": "mongodb://localhost:27017/habitica-dev?replicaSet=rs&directConnection=true&readPreference=secondary",
38+
"TEST_DB_URI": "mongodb://localhost:27017/habitica-test?replicaSet=rs&directConnection=true&readPreference=secondary",
3939
"MONGODB_POOL_SIZE": "10",
4040
"MONGODB_SOCKET_TIMEOUT": "20000",
4141
"NODE_ENV": "development",

docker-compose.mongo-local.yml

+34-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,37 @@
1+
# big thanks to https://pakisan.github.io/posts/docker-compose-mongodb-single-node-replica-set/ <3
2+
3+
version: "3.9"
4+
networks:
5+
mongodb-network:
6+
name: "mongodb-network"
7+
driver: bridge
18
services:
2-
mongo:
3-
image: mongo:7.0
4-
restart: unless-stopped
5-
command: ["--replSet", "rs", "--bind_ip_all", "--port", "27017"]
6-
healthcheck:
7-
test: echo "try { rs.status() } catch (err) { rs.initiate() }" | mongosh --port 27017 --quiet
8-
interval: 10s
9-
timeout: 30s
10-
start_period: 0s
11-
retries: 30
12-
volumes:
13-
- "./mongodb-data2:/data/db"
9+
mongodb:
10+
image: "mongo:7.0"
11+
container_name: "mongodb"
12+
networks:
13+
- mongodb-network
14+
hostname: "mongodb"
1415
ports:
1516
- "27017:27017"
17+
restart: "unless-stopped"
18+
volumes:
19+
- "./mongodb-data:/data/db"
20+
entrypoint: [ "/usr/bin/mongod", "--bind_ip_all", "--replSet", "rs" ]
21+
mongoinit:
22+
image: "mongo:7.0"
23+
container_name: "mongodb_replSet_initializer"
24+
restart: "on-failure" # WITHOUT THIS, the initializer tries only once and fails
25+
depends_on:
26+
- mongodb
27+
networks:
28+
- mongodb-network
29+
30+
command: >
31+
mongosh --host mongodb:27017 --eval "rs.initiate({
32+
_id: \"rs\",
33+
members: [
34+
{_id: 0, host: \"mongodb\"}
35+
]
36+
})"
37+

0 commit comments

Comments
 (0)