Last active
October 9, 2023 07:26
-
-
Save obbaeiei/e44526aa0e4af6c469943015f15079fd to your computer and use it in GitHub Desktop.
Easy Works docker compose create mongo's replica localhost - use with setup.sh
This file contains 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
docker compose up -d |
This file contains 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' | |
services: | |
mongosetup: | |
image: mongo | |
depends_on: | |
- mongo1 | |
- mongo2 | |
- mongo3 | |
volumes: | |
- ./setup.sh:/scripts/setup.sh | |
restart: 'no' | |
entrypoint: ['bash', '/scripts/setup.sh'] | |
mongo1: | |
hostname: mongo1 | |
container_name: localmongo1 | |
image: mongo | |
expose: | |
- 27011 | |
ports: | |
- 27011:27011 | |
restart: always | |
entrypoint: ['/usr/bin/mongod', '--port', '27011', '--bind_ip_all', '--replSet', 'rs0'] | |
mongo2: | |
hostname: mongo2 | |
container_name: localmongo2 | |
image: mongo | |
expose: | |
- 27012 | |
ports: | |
- 27012:27012 | |
restart: always | |
entrypoint: ['/usr/bin/mongod', '--port', '27012', '--bind_ip_all', '--replSet', 'rs0'] | |
mongo3: | |
hostname: mongo3 | |
container_name: localmongo3 | |
image: mongo | |
expose: | |
- 27013 | |
ports: | |
- 27013:27013 | |
restart: always | |
entrypoint: ['/usr/bin/mongod', '--port', '27013', '--bind_ip_all', '--replSet', 'rs0'] |
This file contains 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
127.0.0.1 mongo1 | |
127.0.0.1 mongo2 | |
127.0.0.1 mongo3 |
This file contains 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
echo "sleeping for 10 seconds" | |
sleep 10 | |
echo mongo_setup.sh time now: `date +"%T" ` | |
mongo --host mongo1:27011 <<EOF | |
var cfg = { | |
"_id": "rs0", | |
"version": 1, | |
"members": [ | |
{ | |
"_id": 0, | |
"host": "mongo1:27011", | |
"priority": 2 | |
}, | |
{ | |
"_id": 1, | |
"host": "mongo2:27012", | |
"priority": 0 | |
}, | |
{ | |
"_id": 2, | |
"host": "mongo3:27013", | |
"priority": 0 | |
} | |
] | |
}; | |
rs.initiate(cfg); | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
* IMPORTANT *
Add 3 lines in
/etc/hosts
sudo vi /etc/hosts