-
-
Save mrsinguyen/402811772f5a00304c26130caddad2ff to your computer and use it in GitHub Desktop.
Mongo 7 with a replica set with only one node in docker compose
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "3.7" | |
services: | |
# simple | |
mongo: | |
image: mongo | |
command: mongod --replSet rs0 --bind_ip_all | |
healthcheck: | |
test: | | |
mongosh --eval "try { rs.status().ok } catch (e) { rs.initiate({ _id: 'rs0', members: [{ _id: 0, host: 'localhost:27017' }] }).ok }" | |
start_period: 0s | |
interval: 500ms | |
timeout: 5s | |
retries: 5 | |
ports: [27017:27017] | |
volumes: | |
- ./mongodb/data:/data/db | |
# with auth | |
mongo: | |
image: mongo | |
entrypoint: > | |
/bin/bash -c ' | |
openssl rand -base64 756 > /data/keyfile && | |
chmod 400 /data/keyfile && | |
chown mongodb:mongodb /data/keyfile && | |
/usr/local/bin/docker-entrypoint.sh mongod --replSet rs0 --keyFile /data/keyfile --bind_ip_all' | |
healthcheck: | |
test: > | |
mongosh | |
-u $${MONGO_INITDB_ROOT_USERNAME} | |
-p $${MONGO_INITDB_ROOT_PASSWORD} | |
--eval "try { rs.status().ok } catch (e) { rs.initiate({ _id: 'rs0', members: [{ _id: 0, host: 'localhost:27017' }] }).ok }" | |
start_period: 0s | |
interval: 500ms | |
timeout: 5s | |
retries: 5 | |
ports: [27017:27017] | |
environment: | |
- MONGO_INITDB_ROOT_USERNAME=root | |
- MONGO_INITDB_ROOT_PASSWORD=example | |
volumes: | |
- ./mongodb/data:/data/db |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment