-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker-compose.yml
33 lines (32 loc) · 1.57 KB
/
docker-compose.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
services:
mongo:
# Initialise a Mongo cluster with a replicaset of 1 node.
# Based on https://medium.com/workleap/the-only-local-mongodb-replica-set-with-docker-compose-guide-youll-ever-need-2f0b74dd8384
# Since we are using transactions, we require a replicaset. Local dev with docker compose uses 1 node below, but our live
# environments have multiple nodes.
# The replicaset needs initialising, so the healthcheck can be hijacked to initialise this so that it can keep retrying
# until the operation is successful (might need to wait a while after container boot for this to work, hence the interval/retries)
# WARNING: do not turn on authentication, otherwise will need to deal with generating key pairs and sharing them between
# the replicaset nodes. For local development this is overkill, so just turn off auth and connect to Mongo without creds.
image: mongo:6.0
command: ["--replSet", "rs0", "--bind_ip_all", "--port", "27017"]
restart: unless-stopped
ports:
- 27017:27017
healthcheck:
test: echo "try { rs.status() } catch (err) { rs.initiate({_id:'rs0',members:[{_id:0,host:'mongo:27017'}]}) }" | mongosh --port 27017 --quiet
interval: 5s
timeout: 30s
start_period: 0s
start_interval: 1s
retries: 30
environment:
MONGO_INITDB_DATABASE: forms-manager
mongo-express:
image: mongo-express
restart: unless-stopped
ports:
- 8081:8081
environment:
ME_CONFIG_MONGODB_URL: mongodb://mongo:27017/?replicaSet=rs0&directConnection=true
ME_CONFIG_BASICAUTH: false