Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sovietspy2/fcdb8b13317185d4e21ef44a1b5412e9 to your computer and use it in GitHub Desktop.
Save sovietspy2/fcdb8b13317185d4e21ef44a1b5412e9 to your computer and use it in GitHub Desktop.
Mongo Replica Set docker compose
STANDALONE -> REPLICA SET TUTORIAL
1. GENERATE KEY:
openssl rand -base64 756 > <path-to-keyfile>
chmod 400 file.key
2. MODIFY DOCKER COMPOSE
version: "3"
services:
localmongo1:
hostname: mongo1
container_name: localmongo1
image: mongo:4.2
ports:
- "27011:27017"
volumes:
- test:/data/db
- ./file.key:/data/file.key
command: --quiet --storageEngine wiredTiger --auth
entrypoint: [ "/usr/bin/mongod","--keyFile", "/data/file.key", "--bind_ip_all", "--replSet", "rs0" ]
restart: always
localmongo2:
hostname: mongo2
container_name: localmongo2
image: mongo:4.2
ports:
- "27012:27017"
volumes:
- test2:/data/db
- ./file.key:/data/file.key
command: --quiet --storageEngine wiredTiger --auth
entrypoint: [ "/usr/bin/mongod","--keyFile", "/data/file.key", "--bind_ip_all", "--replSet", "rs0" ]
restart: always
localmongo3:
hostname: mongo3
container_name: localmongo3
image: mongo:4.2
ports:
- "27013:27017"
volumes:
- test3:/data/db
- ./file.key:/data/file.key
command: --quiet --storageEngine wiredTiger --auth
entrypoint: [ "/usr/bin/mongod","--keyFile", "/data/file.key", "--bind_ip_all", "--replSet", "rs0" ]
restart: always
volumes:
test:
test2:
test3:
3. go to
docker exec -it localmongo1 /bin/bash
mongo -u superAdmin -p superAdmin
rs.initiate({
_id : 'rs0',
members: [
{ _id : 0, host : "PUBLICIP:27011" },
{ _id : 1, host : "PUBLICIP:27012" },
{ _id : 2, host : "PUBLICIP:27013" }
]
})
get IP from ifconfig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment